0

I want to do an inner join in my hql query but i've got this error :

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ( ...

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
             ...

The query works in sqldeveloper

ramsey_lewis
  • 558
  • 8
  • 25

2 Answers2

0

Just checking the query you have posted, I think you have to close the parenthesis of new myDto after col2, because in that query you have posted is not closed:

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
             ...
mlg
  • 5,248
  • 1
  • 14
  • 17
0

Hibernate doesn't seem to support inner join with followed by select Inner join with select on HQL I manage to make it work :

 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)
Community
  • 1
  • 1
ramsey_lewis
  • 558
  • 8
  • 25