@Where with @SecondaryTable 不适用于 Hibernate
@Where with @SecondaryTable does not work with Hibernate
我的模型中存在一对多关系,其中子实体存储在两个 table 中。
@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
子句中,它应该引用两个 table 中的列:col1
在 table 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
与两个 table 一起工作,或者有什么解决方法吗?
虽然有一些要求:
- 我正在使用 informix 作为底层数据库并且具有只读访问权限。
- 我知道,它可以通过原生 SQL 甚至 JPQL / criteria API 等等来解决,但是这样做会让我重写很多核心。我想避免它。
我的模型中存在一对多关系,其中子实体存储在两个 table 中。
@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
子句中,它应该引用两个 table 中的列:col1
在 table 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
与两个 table 一起工作,或者有什么解决方法吗?
虽然有一些要求:
- 我正在使用 informix 作为底层数据库并且具有只读访问权限。
- 我知道,它可以通过原生 SQL 甚至 JPQL / criteria API 等等来解决,但是这样做会让我重写很多核心。我想避免它。