'Oracle SQL query working in console but not working in HQL

I'm not sur why my SQL query works fine on Oracle console, but not with HQL.

Here's the query as I run it in my Oracle console :

select distinct table1.*
            from TABLE1 table1, TABLE2 table2
            where table1.ID in (
               select max(table2.RID_TABLE2) from TABLE2 table2 group by RID_OBJECT
            );

This query returns 5 rows, and for some reason, the exact same query in HQL returns 6 rows.

Here is the HQL query:

@Query(name = "select distinct table1.*
            from TABLE1 table1, TABLE2 table2
            where table1.ID in (
               select max(table2.RID_TABLE2) from TABLE2 table2 group by RID_OBJECT
            )")
Set<Object> findTable1ByTable2();

From what I've seen here, it might be related to the fact that I use a subquery in my where clause, and it seems like HQL queries do not allow it.

Basically, it seems like the following part of my 'where' my query is simply ignored with HQL table1.ID in (select max(table2.RID_TABLE2) from TABLE2 table2 group by RID_OBJECT).

My goal is to have both my SQL and HQL queries return 5 rows.

Is there a solution to this ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source