【发布时间】:2019-02-06 11:08:09
【问题描述】:
我的模型中存在一对多关系,其中子实体存储在两个表中。
@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 使用两个表或有任何解决方法?
不过有一些要求:
- 我使用 informix 作为底层数据库,并且具有只读访问权限。
- 我知道,它可以通过原生 SQL 甚至 JPQL/criteria API 等来解决,但是这样做会让我重写很多核心。我想避免它。
【问题讨论】:
标签: java sql hibernate jpa informix