我的实体定义如下:
父母:
@Entity
@Table( name = "Case" )
public class Case implements Serializable {
@Id
@Size ( max = 40 )
private String caseid;
.....
@OneToMany ( cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true )
@JoinColumn ( name = "caseid" )
List< CaseFollowup > followups = new ArrayList<>();
.....
}
儿童IdClass
public class CaseDetailPK implements Serializable {
private String caseid;
private String detailid;
.....
@Override
public boolean equals( Object o ) {
.....
}
@Override
public int hashCode() {
.....
}
}
孩子
@Entity
@Table ( name = "casefollowup" )
@IdClass ( CaseDetailPK .class )
public class CaseFollowup implements Serializable {
@Id
@Size ( max = 40 )
private String caseid;
@Id
@Size ( max = 40 )
private String detailid;
.....
}
在这里我遇到两个问题:
List<Case> cases = caseRepository.findAll();
cases.getFollowups()返回:
unable to evaluate the expression method threw 'org.hibernate.lazyinitializationexception' exception.
org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: NULL not allowed for column "CASEID"; SQL statement:
update casefollowup set caseid=null where adrcaseid=?
没有任何线索来解决它们。有人可以帮我解决这些问题吗?非常感谢。