2013-02-11 54 views
0

Embeddable類有另一個Entity O/R映射註釋時,我無法使用EclipseLink生成DDL。 如何爲我的O/R映射生成DDL?EclipseLink 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; 
} 

Township.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)]) 

回答

1

如果我正確理解你,你希望鄉鎮成爲一個正常的獨立實體。在這種情況下,您應該從CompanyAddress中的鄉鎮字段中刪除@Embedded註釋。如果你想嵌入它,那麼Township需要一個@Embeddable註解來代替@Entity。

+0

感謝您的幫助,我認爲JPA規範允許'Embedded'類與其他'Entity'進行O/R映射。 – CycDemo 2013-02-13 04:27:20