使用HQL嵌套的select语句

时间:2015-01-13 17:57:21

标签: sql hibernate hql nested-queries

我想基于ProjectPage的两个表中的不同ID将表Project与表ProjectPage连接起来,我正在使用HQL,我尝试了以下内容:

EntityManager em = entityManager();
TypedQuery<Project> q = em.createQuery("SELECT o FROM Project AS o inner join
      (SELECT DISTINCT  pp.id  from ProjectPage) pp" +
      "on o.id=pp.id WHERE LOWER(o.name) LIKE LOWER(:name) "+
      "and ( o.status is null or o.status != :status_val)", Project.class);

我收到以下错误:

ERROR org.hibernate.hql.internal.ast.ErrorCounter : unexpected token: (

我的查询中出现了什么问题?

1 个答案:

答案 0 :(得分:0)

select语句中的表别名可能是吗?

SELECT o FROM Project AS o

你的意思是

SELECT o.* FROM Projects AS o