From 1126438604a4e893a9e37df92d9217b093352bf3 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Fri, 23 Jun 2023 13:10:48 +0200 Subject: [PATCH] HHH-16754 Add test for issue --- .../test/set/SetOperationJpaCriteriaTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/set/SetOperationJpaCriteriaTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/set/SetOperationJpaCriteriaTest.java index 6cdc7dea0d..5ca734acdd 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/set/SetOperationJpaCriteriaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/set/SetOperationJpaCriteriaTest.java @@ -16,6 +16,7 @@ import org.hibernate.testing.orm.domain.StandardDomainModel; import org.hibernate.testing.orm.domain.gambit.EntityOfLists; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.Jira; import org.hibernate.testing.orm.junit.RequiresDialectFeature; import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; @@ -160,4 +161,33 @@ public class SetOperationJpaCriteriaTest { } ); } + + @Test + @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUnion.class) + @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsOrderByInSubquery.class) + @Jira( "https://hibernate.atlassian.net/browse/HHH-16754" ) + public void testUnionAllSubqueryOrderByPath(SessionFactoryScope scope) { + scope.inSession( + session -> { + HibernateCriteriaBuilder cb = session.getCriteriaBuilder(); + + JpaCriteriaQuery query1 = cb.createQuery( EntityOfLists.class ); + JpaRoot root1 = query1.from( EntityOfLists.class ); + query1.where( cb.equal( root1.get( "id" ), 1 ) ); + + JpaCriteriaQuery query2 = cb.createQuery( EntityOfLists.class ); + JpaRoot root2 = query2.from( EntityOfLists.class ); + query2.where( cb.equal( root2.get( "id" ), 2 ) ); + + List list = session.createQuery( + cb.unionAll( + query1, + query2.orderBy( cb.asc( root2.get("name") ) ) + .fetch( 1 ) + ) + ).list(); + assertThat( list.size(), is( 2 ) ); + } + ); + } }