From 0c47e99eb44d66932267f84f8fe65a3dc17c0f3d Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 6 Apr 2022 17:39:30 +0200 Subject: [PATCH] HHH-14819 Add test for issue --- .../test/limit/Oracle12LimitTest.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/limit/Oracle12LimitTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/limit/Oracle12LimitTest.java b/hibernate-core/src/test/java/org/hibernate/test/limit/Oracle12LimitTest.java new file mode 100644 index 0000000000..3977776e4a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/limit/Oracle12LimitTest.java @@ -0,0 +1,79 @@ +package org.hibernate.test.limit; + +import java.util.List; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.Root; + +import org.hibernate.dialect.Oracle12cDialect; + +import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +@RequiresDialect(Oracle12cDialect.class) +@TestForIssue(jiraKey = "HHH-14819") +public class Oracle12LimitTest extends BaseCoreFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + Person.class, + Travel.class + }; + } + + @Test + public void testLimit() { + inTransaction( + session -> { + final CriteriaBuilder criteriabuilder = session.getCriteriaBuilder(); + final CriteriaQuery criteriaquery = criteriabuilder.createQuery(); + final Root personRoot = criteriaquery.from( Person.class ); + final Join travels = personRoot.join( "travels", JoinType.LEFT ); + + criteriaquery.select( personRoot ). + where( criteriabuilder.or( criteriabuilder.equal( personRoot.get( "name" ), "A" ) ) ) + .distinct( true ); + + criteriaquery.orderBy( criteriabuilder.desc( criteriabuilder.upper( travels.get( "destination" ) ) ) ); + + final TypedQuery createQuery = session.createQuery( criteriaquery ); + + createQuery.setFirstResult( 3 ).setMaxResults( 10 ).getResultList(); + } + ); + } + + @Entity(name = "Person") + public class Person { + @Id + private Long id; + + @OneToMany + private List travels; + + public Person() { + } + + private String name; + } + + @Entity(name = "Travel") + public class Travel { + @Id + private Integer id; + + private String destination; + + public Travel() { + } + } +}