【发布时间】:2021-03-10 20:57:48
【问题描述】:
我有以下课程
public class User {
@OneToMany(
fetch = FetchType.EAGER,
mappedBy = "user",
cascade = CascadeType.ALL
)
private Set<UserSession> sessions;
public UserSession login() {
UserSession session = new UserSession();
session.setUser(this);
session.persistAndFlush();
this.persistAndFlush();
return session;
}
....
public class UserSession {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
protected User user;
如您所见,我正在从它的一侧添加会话。有时在其他时候我得到了
caused by: org.hibernate.HibernateException: collection was evicted
如何正确做?
【问题讨论】:
标签: java jpa one-to-many many-to-one bidirectional-relation