2017-02-13 82 views
0

我想要做内部在我的HQL查询加入,但我得到了这个错误:HQL:内部连接

产生的原因:org.hibernate.hql.internal.ast.QuerySyntaxException:意外的标记: (...

SELECT new myDto(
       col1, col2 
      FROM table1,table2 
      INNER JOIN (
       SELECT foo, bar, ... max(nb) as numberBar 
       FROM table1 
       GROUP BY foo, bar ... 
      ) myAlias 

      ON table1.foo = myAlias.foo 
      AND table1.bar = myAlias.bar 
      ... 

查询中的SQLDeveloper工作

回答

0

只是检查您已发布查询,我觉得你有后关闭的new myDto括号,因为在查询您已发布未闭:

SELECT new myDto(
       col1, col2) 
      FROM table1,table2 
      INNER JOIN (
       SELECT foo, bar, ... max(nb) as numberBar 
       FROM table1 
       GROUP BY foo, bar ... 
      ) myAlias 

      ON table1.foo = myAlias.foo 
      AND table1.bar = myAlias.bar 
      ... 
+0

其实, HQL似乎不支持'inner join'与'select':/。我会发布我的解决方法。谢谢 – user2203384

0

休眠似乎并不支持inner join与随后select Inner join with select on HQL 我管理,使其工作:

SELECT new myDto(
    //usual colums selection here 
    from table1, table2 
where ... 
AND .... 

// solution here without inner join 
AND ( table1.foo, table1.bar, nb) 
IN (select foo, bar, max(nb) as number 
    from table1  
    group by foo, bar)