开发者

OpenJPA: Super class property not found for AttributeOverride

When trying to map an inherited property using AttributeOverride annotation, OpenJPA throws an error that it cannot find the property in the super class. I'm not sure how to map this the correct way.

Error

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

Code

开发者_运维知识库
@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", 
                 column=@Column(name="mailingAddressLine")),
            @AttributeOverride(name="additionalAddressLine", 
                  column=@Column(name="mailingAddressLine2")),
            @AttributeOverride(name="city", 
                  column=@Column(name="mailingAddressCity")),
            @AttributeOverride(name="state", 
                  column=@Column(name="mailingAddressState")),
            @AttributeOverride(name="zip", 
                  column=@Column(name="mailingAddressZip")),
    })
    private ExtendedAddress mailingAddress;

    @Embedded
    @AttributeOverrides(value={
            @AttributeOverride(name="addressLine", 
                 column=@Column(name="billingAddressLine")),
            @AttributeOverride(name="city", 
                  column=@Column(name="billingAddressCity")),
            @AttributeOverride(name="state", 
                  column=@Column(name="billingAddressState")),
            @AttributeOverride(name="zip", 
                  column=@Column(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
)


Change the access level in your Embeddables (Address and ExtendedAddress) from private to protected or default.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜