Java EclipseLink DDL生成错误
当一个Java EclipseLink DDL生成错误,java,jpa,eclipselink,Java,Jpa,Eclipselink,当一个可嵌入的类有另一个实体O/R映射注释时,我无法使用EclipseLink生成DDL。 如何为我的O/R映射生成DDL Company.java @Entity public class Company implements Serializable { ..... @Embedded private CompanyAddress address; } CompanyAddress.java @Embeddable public class CompanyAddr
可嵌入的
类有另一个实体
O/R映射注释时,我无法使用EclipseLink
生成DDL。
如何为我的O/R映射生成DDL
Company.java
@Entity
public class Company implements Serializable {
.....
@Embedded
private CompanyAddress address;
}
CompanyAddress.java
@Embeddable
public class CompanyAddress implements Serializable {
.....
@Embedded
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "TOWNSHIP_ID", referencedColumnName = "ID")
private Township township;
}
town.java
@Entity
public class Township implements Serializable {
.....
}
当我生成时,我得到以下错误:
Exception [EclipseLink-195] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The shared class org.ace.insurance.system.common.company.CompanyAddress must not reference the isolated class org.ace.insurance.system.common.township.Townsh
ip.
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[township]
Descriptor: RelationalDescriptor(org.ace.insurance.system.common.company.CompanyAddress --> [DatabaseTable(COMPANY)])
如果我理解正确的话,你希望乡镇成为一个正常的独立实体。在这种情况下,您应该从CompanyAddress中的Town字段中删除@Embedded注释。如果您想将其嵌入,则需要@embedded注释而不是@Entity。谢谢您的帮助,我认为JPA规范允许
embedded
类与其他实体进行O/R映射。