2011-08-04 38 views
2

当试图使用AttributeOverride注释映射继承的属性时,OpenJPA会抛出一个错误,即它无法在超类中找到该属性。我不知道如何以正确的方式绘制这个图。OpenJPA:AttributeOverride找不到超类属性

错误

Embedded property "Order.mailingAddress" declares a mapping override for "addressLine", but that is not a persistent property in the embedded type.

代码

@Embeddable 
public class Address{ 
    private String addressLine; 
    private String city; 
    private String state; 
    private String zip; 

    //getters and setters 
} 

@Embeddable 
public class ExtendedAddress extends Address{ 
    private String additionalAddressLine; 

    //getters and setters 
} 

@Entity 
public class Order { 
    @Id 
    private id; 

    @OneToOne 
    private Customer customer; 

    @Embedded 
    @AttributeOverrides(value={ 
      @AttributeOverride(name="addressLine", 
       [email protected](name="mailingAddressLine")), 
      @AttributeOverride(name="additionalAddressLine", 
        [email protected](name="mailingAddressLine2")), 
      @AttributeOverride(name="city", 
        [email protected](name="mailingAddressCity")), 
      @AttributeOverride(name="state", 
        [email protected](name="mailingAddressState")), 
      @AttributeOverride(name="zip", 
        [email protected](name="mailingAddressZip")), 
    }) 
    private ExtendedAddress mailingAddress; 

    @Embedded 
    @AttributeOverrides(value={ 
      @AttributeOverride(name="addressLine", 
       [email protected](name="billingAddressLine")), 
      @AttributeOverride(name="city", 
        [email protected](name="billingAddressCity")), 
      @AttributeOverride(name="state", 
        [email protected](name="billingAddressState")), 
      @AttributeOverride(name="zip", 
        [email protected](name="billingAddressZip")), 
    }) 
    private Address billingAddress; 

    //getters and setters 
    //hashcode 
    //equals 
} 

SQL

CREATE TABLE Orders (
    id INT PRIMARY KEY GENERATED ALWAYS, 
    mailingAddressLine VARCHAR(45) DEFAULT NULL, 
    mailingAddressLine2 VARCHAR(45) DEFAULT NULL, 
    mailingAddressCity VARCHAR(45) DEFAULT NULL, 
    mailingAddressState CHAR(2) DEFAULT NULL, 
    mailingAddressZip CHAR(9) DEFAULT NULL, 
    billingAddressLine VARCHAR(45) DEFAULT NULL, 
    billingAddressCity VARCHAR(45) DEFAULT NULL, 
    billingAddressState CHAR(2) DEFAULT NULL, 
    billingAddressZip CHAR(9) DEFAULT NULL 
) 

回答

2

改变你Embeddab的访问级别les(地址和ExtendedAddress)从私人保护或默认。

+0

你是对的!非常感谢你! –