Since the Version 6.2.4 the sql is wrong if you have follwing
* Oracle DB * EntityA * EntityB * EntityA has many-to-one relationship to EntityB * you select distinct EntityA.entityB and sets max results to something e.g. 2
Real Example with Testcase attached hql: {code:java} var list = em.createQuery("select distinct a.entityB from EntityA a ", EntityA.class) .setMaxResults(2) .getResultList(); {code}
h2. Produced sql was correct in 6.2.1, 6.2.3
{code:sql} select * from (select distinct e2_0.tableBId c0 from TABLE_A e1_0 join TABLE_B e2_0 on e2_0.tableBId=e1_0.tableBId) where rownum<=? {code}
h2. Since 6.2.4 the produces SQL is wrong (!)
{code:sql} select * from (select distinct e2_0.tableBId c0,rownum rn from TABLE_A e1_0 join TABLE_B e2_0 on e2_0.tableBId=e1_0.tableBId) r_0_ where r_0_.rn<=? order by r_0_.rn {code} this is wrong because if you include rownum as column and distinct over it then all rows will become unique even the real duplicates
|
|