在我的应用程序中,用户可以有一个收藏夹列表。最喜欢的列表可以包含多种球。问题是,当我尝试删除User表(session.delete(user))的记录时,它将删除所有添加到该用户的收藏夹列表中的球的记录。
但是,它只应删除用户的选定记录,用户的收藏夹列表以及该收藏夹列表的收藏夹项,而不是球表中的任何记录
人际关系
Each User must have only one FavoritesList
Each FavoritesList may have zero to many FavoriteItems
Each FavoriteItems must have only one ball
Each ball can be belong to zero to many FavoriteItems
班级
@Entity
public class User{
....
@OneToOne(cascade = CascadeType.ALL)
protected FavoritesList favoritesList;
public User{
...
this.favoritesList = new FavoritesList();
}
....
}
@Entity
public class FavoritesList {
...
@OneToMany
@LazyCollection(LazyCollectionOption.FALSE)
private List<FavoriteItems> items;
public FavoritesList(){
this.items = new ArrayList();
}
...
}
@Entity
public class FavoriteItems {
...
@ManyToOne
private Ball ball;
...
}
最佳答案
确保您还有其他保留球的列表,因为没有为@ManyToOne over Ball定义级联。