代码之家  ›  专栏  ›  技术社区  ›  Andronicus

@其中@SecondaryTable不适用于Hibernate

  •  2
  • Andronicus  · 技术社区  · 7 年前

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

    @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
    ...
    
    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).
      

    @在哪里 使用两张桌子,或者是否有解决方法?

    但也有一些要求:

    1. 我使用informix作为底层数据库,并且具有只读访问权限。
    1 回复  |  直到 7 年前
        1
  •  2
  •   Vlad Mihalcea    5 年前

    这是由于 HHH-4246 问题

    一个解决办法是替换 @SecondaryTable @OneToOne @MapsId .

    这条路 child2 Child2 您可以使用的实体 @Where @Filter .