2016-12-07 71 views
0

我不能使用Hibernate HQL兩個表的簡單連接:Hibernate的連接生成空SQL 「ON」 條款

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 

} 

我用: 彈簧框架4.2.5.RELEASE

休眠5.1.0.Final

甲骨文11G

回答

2

嘗試這個

查詢查詢= em.createQuery(「從t選擇t t內連接t.ulistTp tp「);

+0

它現在可以工作,但請您解釋您的答案 – Lev

+0

您需要引用定義爲Ulist中屬性的對象。正如您引用了直接的UlistTp類,Hibernate無法識別並使其相同 – murthy