将 @OneToOne 与 @Where 子句映射
我正在尝试按以下方式映射一个实体,
@OneToOne(mappedBy = "localizedLabel")
@JoinColumn(insertable = false, updatable = false)
@WhereJoinTable(clause = "locale='en_US'")
public Localization getEn_US() {
return en_US;
}
我可以确保如果未找到数据,数据将仅返回一个或 null,但 hibernate 似乎忽略我的 @Where 子句:
ERROR com.eventtouch.bc.business.core.log.LoggingInterceptor - org.hibernate.HibernateException: More than one row with the given identifier was found: 4211, for class: com.eventtouch.bc.business.domain.LocalizedLabel
有关如何将 @OneToOne 关系与 @Where 子句映射的任何想法?
谢谢
I am trying to map an entity as following
@OneToOne(mappedBy = "localizedLabel")
@JoinColumn(insertable = false, updatable = false)
@WhereJoinTable(clause = "locale='en_US'")
public Localization getEn_US() {
return en_US;
}
I can assure that the data will return only one or null if the not found, but hibernate seems to ignore my @Where clause:
ERROR com.eventtouch.bc.business.core.log.LoggingInterceptor - org.hibernate.HibernateException: More than one row with the given identifier was found: 4211, for class: com.eventtouch.bc.business.domain.LocalizedLabel
Any ideas on ho to map a @OneToOne relationship with @Where clause?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的@OneToOne似乎没有使用连接表。
在这种情况下,您是否应该使用 @Where 注释而不是 @WhereJoinTable 来过滤连接表的行?
Your @OneToOne does not seem to use a join table.
In that case, shouldn't you use a @Where annotation rather than the @WhereJoinTable that filters rows of a join table ?
当您使用 @JoinColumn 时,会在源表中创建引用列(因为它是一对一关联),这可以避免创建连接表。
When you use
@JoinColumn
reference column is created in source table (as it is one to one association) this avoid creating a join table.