多个嵌入属性中的 jpa AttributeOverride

发布于 2024-12-20 13:38:15 字数 931 浏览 0 评论 0原文

有人可以帮助我设置正确的方法来覆盖扩展实体中的列名称。

可嵌入:

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心激荡 2024-12-27 13:38:15

在最后一个映射中,您的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文