【发布时间】:2020-10-10 15:40:26
【问题描述】:
我有这两个实体
@Entity
@Table(name = "CallSession")
public class CallSession implements Serializable {
private long id;
private List<CallParticipant> members;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@OneToMany(mappedBy = "callSession", fetch = FetchType.LAZY)
public List<CallParticipant> getMembers() {
return members;
}
public void setMembers(List<CallParticipant> members) {
this.members = members;
}
}
@Entity
@Table(name = "CallParticipant")
public class CallParticipant implements Serializable {
private long id;
private CallSession callSession;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@ManyToOne
public CallSession getCallSession() {
return callSession;
}
public void setCallSession(CallSession callSession) {
this.callSession = callSession;
}
}
但是当我调用callSession.getMembers() 方法时,
我得到这个例外:
无法评估表达式 Method throw 'org.hibernate.LazyInitializationException' 异常。
我不知道为什么会出现此错误?为什么会出现此错误,我该如何解决?
【问题讨论】:
标签: java hibernate jpa jpql hibernate-mapping