【问题标题】:HQL fails on joining two tables on a common foreign key columnHQL 无法在公共外键列上连接两个表
【发布时间】:2015-12-23 11:27:26
【问题描述】:

我有两个实体

@Entity
@Table(name="one")
public class One implements Serializable {
  @Id
    @NotNull
    @Column(name = "id")
    private String id;

     @Column(name = "name")
    private String name;

    @Column(name = "title")
    private String title;

    @ManyToOne
    @JoinColumn(name = "three_id")
    private Three three;
}

@Entity
@Table(name="two")
public class Two implements Serializable {
    @Id
    @NotNull
    @Column(name = "id")
    private String id;

     @Column(name = "order")
    private String order;

    @ManyToOne
    @JoinColumn(name = "three_id")
    private Three three;
}

@Entity
@Table(name="three")
public class Three implements Serializable {
  @Id
    @NotNull
    @Column(name = "id")
    private String id;

     @Column(name = "quantity")
    private String quantity;
}

一个命名查询为 select o.name from one o, two tw, three th where tw.order="test" and o.three.id = tw.three.id;

部署此org.hibernate.HibernateException: Errors in named queries时,Jboss 抛出以下错误

目的是我想要基于公共列three_id 的两个表中的行,该列是表“三”中的 id 字段 为什么会失败,我该如何解决。

【问题讨论】:

    标签: hibernate named-query


    【解决方案1】:

    好吧,您似乎没有在查询中的任何地方使用 th,这可能是问题所在。

    这应该可行:

    从一个o,两个tw中选择o.name,其中tw.order="test" and o.three.id = tw.three.id;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-23
      • 2022-08-19
      • 2017-10-19
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      相关资源
      最近更新 更多