多个嵌入属性中的 jpa AttributeOverride
有人可以帮助我设置正确的方法来覆盖扩展实体中的列名称。
可嵌入:
@Embedable
Email
@Column(name = "email_adress")
private string email;
父实体:
@Entity
AddressBook
@Embedded
@AttributeOverrides( {
@AttributeOverride(name="email", column = @Column(name="email_address") )
} )
private Email email
扩展实体:
@Entity
@AttributeOverrides( {
@AttributeOverride(name="email", column = @Column(name="home_email") )
} )
DeluxAddressBook extends AddressBook
@Embeded
@AttributeOverrides( {
@AttributeOverride(name="email", column = @Column(name="work_email") )
} )
private Email workEmail;
在最后一个实体中,我将 workEmail 映射到“work_email”列,这是可以的,但是 home_email 映射到最初在嵌入中定义的列“email_address”。它应该映射到“home_email”列。
我尝试过但没有成功:
@AttributeOverride(name="email.email", column = @Column(name="home_email") )
感谢您的帮助, 杰西
Could someone help me to set the proper way to override a column name in an extended entity.
Embedeable:
@Embedable
Email
@Column(name = "email_adress")
private string email;
Parent entity:
@Entity
AddressBook
@Embedded
@AttributeOverrides( {
@AttributeOverride(name="email", column = @Column(name="email_address") )
} )
private Email email
Extending entity:
@Entity
@AttributeOverrides( {
@AttributeOverride(name="email", column = @Column(name="home_email") )
} )
DeluxAddressBook extends AddressBook
@Embeded
@AttributeOverrides( {
@AttributeOverride(name="email", column = @Column(name="work_email") )
} )
private Email workEmail;
In the last entity I get workEmail mapped to "work_email" column which is OK, however home_email is mapped to column "email_address" defined originally in the embeddable. It should be mapped to a "home_email" column.
I tried w/o success:
@AttributeOverride(name="email.email", column = @Column(name="home_email") )
Thanks for your help,
Jess
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在最后一个映射中,您的 AttributeOverride 名称属性定义了电子邮件的映射,该电子邮件是基类中的字段。
第二个映射应该用于工作电子邮件而不是电子邮件。通过此更改,您应该能够达到预期的结果。
In the last mapping your both AttributeOverride name property defines mapping for email which is field from base class.
Second mapping should be for workEmail not for email. With this change you should be able to achieve desired result.