在我的应用程序中,用户可以拥有一个收藏列表。最喜欢的列表可以有多种球。问题是,当我尝试删除用户表(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;
...
}