这是我的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/