Hibernate 连接生成带有空 "ON" 子句的 sql

Hibernate join produces sql with empty "ON" clause

我无法使用休眠 HQL 对两个表进行简单连接:

Query query =em.createQuery("select t from Ulist t inner join UlistTp tp");

我得到 org.hibernate.exception.SQLGrammarException:

Hibernate: select ulist0_.id as id1_2_, ulist0_.ACTUAL as ACTUAL2_2_, ulist0_.CD as CD3_2_, ulist0_.DT1 as DT4_2_, ulist0_.DT2 as DT5_2_, ulist0_.NAME as NAME6_2_, ulist0_.S1 as S7_2_, ulist0_.FK_LISTTP as FK_LISTTP8_2_ from EXS.U_LIST ulist0_ inner join EXS.U_LISTTP ulisttp1_ on
10:32:46.562 [main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ORA-00936: missing expression

看过之后发现"ON"子句是空的!为什么? 我认为,我的实体映射得很好:

@Entity
@Table(name = "U_LIST", schema="EXS")
public class Ulist implements java.io.Serializable  {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_EXS")
    @SequenceGenerator(name="SEQ_EXS", sequenceName="EXS.SEQ_U_LIST", allocationSize=1) 
    @Column(name = "id", unique=true, updatable = false, nullable = false)
    private Integer id;

    @Column(name = "CD", updatable = true, nullable = true)
    private String cd;

    @Column(name = "NAME", updatable = true, nullable = true)
    private String name;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name="FK_LISTTP", referencedColumnName="ID")
    private UlistTp ulistTp; 
    ...getters
    ...setters
}

@Entity
@Table(name = "U_LISTTP", schema="EXS")
public class UlistTp implements java.io.Serializable  {

    public UlistTp() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_EXS")
    @SequenceGenerator(name="SEQ_EXS", sequenceName="EXS.SEQ_U_LISTTP", allocationSize=1)   
    @Column(name = "id", unique=true, updatable = false, nullable = false)
    private Integer id;

    @Column(name = "CD", updatable = true, nullable = true)
    private String cd;

    @Column(name = "NAME", updatable = true, nullable = true)
    private String name;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name="FK_LISTTP", referencedColumnName="ID")
    @Fetch(FetchMode.SUBSELECT)
    private List<Ulist> ulist = new ArrayList<Ulist>(0);

    ...getters
    ...setters

}

我使用: spring-框架4.2.5.RELEASE

休眠 5.1.0.Final

甲骨文 11G

试试这个

查询查询=em.createQuery("select t from Ulist t inner join t.ulistTp tp");