我有一个实体类证书,它有一个实体类 CertificateProfile。
public class Certificate {
@Id
private String certId;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="certificateProfileId", foreignKey = @ForeignKey(name = "none"))
private CertificateProfile certificateProfile;
}
public class CertificateProfile {
@Id
private Long id;
private String certificateProfileName;
...
}
我正在使用旧数据库。因此,即使 certificateProfileId 列包含 certificateProfile 的 id,也没有外键约束。当我尝试通过CertificateDataRepository.findAll(). 我得到javax.persistence.EntityNotFoundException: Unable to find CertificateProfile with id 0
我试图将 fetchType 设置为 Lazy 但我收到此错误:
could not initialize proxy [CertificateProfileData#1508963102] - no Session