Waldemar.Maier (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6329a18...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMWIwNTI5NTMw...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16800?atlOrigin=eyJpIjoiMWIwNT...
) HHH-16800 (
https://hibernate.atlassian.net/browse/HHH-16800?atlOrigin=eyJpIjoiMWIwNT...
) Wrong SELECT Statement Generation with setMaxResults in Hibernate 6.2.4 (Oracle DB) (
https://hibernate.atlassian.net/browse/HHH-16800?atlOrigin=eyJpIjoiMWIwNT...
)
Change By: Waldemar.Maier (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6329a18...
)
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
Configuration
{code:xml} <property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle12cDialect"/>
<property name="hibernate.connection.driver_class"
value="oracle.jdbc.OracleDriver"/>{code}
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
(
https://hibernate.atlassian.net/browse/HHH-16800#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16800#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100226- sha1:d46780b )