作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的模型中有一对多关系,其中子实体存储在两个表中。
@Entity
@Table(name = "child1")
@SecondaryTable(name = "child2", pkJoinColumns = {
@PrimaryKeyJoinColumn(name = "id1", referencedColumnName = "id1"),
@PrimaryKeyJoinColumn(name = "id2", referencedColumnName = "id2")})
@Where(clause = "col1 is not null and col2 is not null")
@Data
@Immutable
public class Child implements Serializable {...}
Child
实体与 Parent
实体一起急切地获取。问题出在 @Where
子句中,该子句应该引用两个表中的列:col1
位于表 child1
和 col2
中位于 child2
中。这会引发以下错误:
ERROR 12333 --- [nio-8183-exec-7] o.h.engine.jdbc.spi.SqlExceptionHelper : Column (col2) not found in any table in the query (or SLV is undefined).
java.sql.SQLException: null
...
@Where(clause = "col1 is not null")
提供正确的映射并且不会产生错误。使用 @Where(clause = "child1.col1 is not null and child2.col2 is not null")
会出现以下错误:
Column (child1) not found in any table in the query (or SLV is undefined).
如何使 @Where
使用两个表或有任何解决方法吗?
但是有一些要求:
最佳答案
这是由于 HHH-4246问题。
解决方法是使用 @MapsId
将 @SecondaryTable
替换为 @OneToOne
关联。 .
这样,child2
表就成为 Child2
实体,您可以对其使用 @Where
或 @Filter
.
关于java - @Where 与 @SecondaryTable 不适用于 Hibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54552156/
我是一名优秀的程序员,十分优秀!