OpenJPA:找不到 AttributeOverride 的超类属性
当尝试使用 AttributeOverride 注释映射继承的属性时,OpenJPA 会抛出错误,指出它无法在超类中找到该属性。我不确定如何以正确的方式映射它。
错误
嵌入属性“Order.mailingAddress”声明了“addressLine”的映射覆盖,但这不是嵌入类型中的持久属性。
代码
@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
)
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
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 Embeddables 中的访问级别(地址和扩展地址)从私有更改为受保护或默认。
Change the access level in your Embeddables (Address and ExtendedAddress) from private to protected or default.