@Where与@SecondaryTable不与Hibernate一起工作

问题描述 投票:1回答:1

有一个在我的模型,其中儿童实体存储在两个表一个一对多的关系。

@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是在表child1col2child2。这引发以下错误:

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
...
  1. 只有使用:@Where(clause = "col1 is not null")给出任何错误propper映射和结果。
  2. 使用@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两个表工作,或者是有什么解决方法吗?

有一些要求,但:

  1. 我使用Informix作为基础数据库,并已只读访问。
  2. 我知道,它可以通过本地SQL甚至JPQL /标准API等来解决,但这样做会令我重写了很多核心的。我想避免它。
java sql hibernate jpa informix
1个回答
2
投票

这是由于HHH-4246问题。

一种解决方法是用@SecondaryTable更换@OneToOne with @MapsId association。这样,child2表成为您可以使用Child2@Where@Filter实体。退房this article for more details有关使用这些注解。

© www.soinside.com 2019 - 2024. All rights reserved.