Delete Not Working with JpaRepository

前端 未结 12 2086
情书的邮戳
情书的邮戳 2020-12-07 11:55

I have a spring 4 app where I\'m trying to delete an instance of an entity from my database. I have the following entity:

@Entity
public class Token impleme         


        
12条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 12:46

    You need to add PreRemove function ,in the class where you have many object as attribute e.g in Education Class which have relation with UserProfile Education.java

    private Set userProfiles = new HashSet(0);
    
    @ManyToMany(fetch = FetchType.EAGER, mappedBy = "educations")
    public Set getUserProfiles() {
        return this.userProfiles;
    }
    
    @PreRemove
    private void removeEducationFromUsersProfile() {
        for (UsersProfile u : usersProfiles) {
            u.getEducationses().remove(this);
        }
    }
    

提交回复
热议问题