java - 使用 jpa 生成实体时显示错误

标签 java jpa eclipselink

这是我的EmployeeDetailEntity.java 类。其中我使用 @OnetoOne 注释与名为 GenderEntity 的其他实体建立关系。以下是我的EmployeeDetailEntity

@OneToOne
@JoinColumn(name="GenderEntity",referencedColumnName="id")
private GenderEntity gen;

这是我的 GenderEntity.java 类,其中我映射了与 EmployeedetailEntity.java (ReferencedById="id") 的关系,其中 id是主键。

@OneToOne(mappedBy="gen",cascade=CascadeType.ALL)
private EmployeeDetailEntity empdtl;

从实体生成表时出现错误(生成失败,请参阅控制台了解更多信息),我的控制台如下:

Exception [EclipseLink-93] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [GENDERENTITY] is not present in this descriptor.
Descriptor: RelationalDescriptor(entities.PatientTypeEntity --> [DatabaseTable(PATIENTTYPEENTITY)])

Exception [EclipseLink-93] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [SHOPPROFILEENTITY] is not present in this descriptor.
Descriptor: RelationalDescriptor(entities.EmployeeDetailEntity --> [DatabaseTable(EMPLOYEEDETAILENTITY)])

Exception [EclipseLink-41] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A non-read-only mapping must be defined for the sequence number field.
Descriptor: RelationalDescriptor(entities.PatientTypeEntity --> [DatabaseTable(PATIENTTYPEENTITY)])

Exception [EclipseLink-41] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A non-read-only mapping must be defined for the sequence number field.
Descriptor: RelationalDescriptor(entities.EmployeeDetailEntity --> [DatabaseTable(EMPLOYEEDETAILENTITY)])

描述符异常:

Local Exception Stack: 
Exception [EclipseLink-93] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [GENDERENTITY] is not present in this descriptor.
Descriptor: RelationalDescriptor(entities.PatientTypeEntity --> [DatabaseTable(PATIENTTYPEENTITY)])

最佳答案

问题出在下面一行:

@JoinColumn(name="GenderEntity",referencedColumnName="id")

执行以下操作:

有趣的部分是 @JoinColumn 注释,它指定作为外键的本地列 (EMPLOYEE_DETAIL_ID) 以及它对应于外部表的哪一列(EMPLOYEE_ID)。

所以我假设您的 GENDER 表中有 EMPLOYEE_DETAIL_ID,它是引用 EMPLOYEE_DETAIL 表和 EMPLOYEE_ID 的主键的外键是 EMPLOYEE_DETAIL 表中的列。因此,您的最终映射将如下所示:

@JoinColumn(name="EMPLOYEE_DETAIL_ID",referencedColumnName="EMPLOYEE_ID ")

并确保“gen”是EmployeeDetailEntity.java中的一个属性,如下所示:

GenderEntity gen;

关于java - 使用 jpa 生成实体时显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24547830/

相关文章:

java - 当另一个事务删除惰性子级时的 JPA-Hibernate 行为

java - Firebase Cloud Messaging 多次发送上游消息,尽管我发送了确认

java - mSlider.startIndeterminate() 不起作用

java - JPQL 中对象构造函数内的子查询

java - 线程 "AWT-EventQueue-0"中的 ConcurrentModificationException ?

jpa - java.lang.IllegalStateException : No explicit selection and an implicit one could not be determined

java - JPA:保存具有多对一的实体时违反主键

java - JPA 错误 : relation does not exist

java - @ManyToMany - 数据不会保存在数据库中

java - 类似子句 JPQL 中的参数