有一个在我的模型,其中儿童实体存储在两个表一个一对多的关系。
@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")
给出任何错误propper映射和结果。@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问题。
一种解决方法是用@SecondaryTable
更换@OneToOne
with @MapsId
association。这样,child2
表成为您可以使用Child2
或@Where
的@Filter
实体。退房this article for more details有关使用这些注解。