我无法使用hibernate 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-framework 4.2.5.RELEASE
Hibernate 5.1.0.Final
Oracle 11G
答案 0 :(得分:4)
试试这个
查询查询= em.createQuery(“选择来自Ulist t inner join t.ulistTp tp”);