diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/generics/GenericPathComparisonTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/generics/GenericPathComparisonTest.java index 3ec94f1ab2..d2441d4182 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/generics/GenericPathComparisonTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/generics/GenericPathComparisonTest.java @@ -8,14 +8,10 @@ package org.hibernate.orm.test.annotations.generics; import java.io.Serializable; -import org.hibernate.cfg.AvailableSettings; - import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.Jira; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -26,7 +22,9 @@ import jakarta.persistence.MappedSuperclass; import jakarta.persistence.TypedQuery; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Path; import jakarta.persistence.criteria.Root; +import jakarta.persistence.criteria.Subquery; import static org.assertj.core.api.Assertions.assertThat; @@ -110,6 +108,29 @@ public class GenericPathComparisonTest { } ); } + @Test + @Jira( "https://hibernate.atlassian.net/browse/HHH-17959" ) + public void testInSubquery(SessionFactoryScope scope) { + scope.inTransaction( session -> executeQuery( session.createQuery( + "from UserEntity where id in (select id from UserEntity where id = 1)", + UserEntity.class + ) ) ); + } + + @Test + @Jira( "https://hibernate.atlassian.net/browse/HHH-17959" ) + public void testInSubqueryCriteria(SessionFactoryScope scope) { + scope.inTransaction( session -> { + final CriteriaBuilder cb = session.getCriteriaBuilder(); + final CriteriaQuery query = cb.createQuery( UserEntity.class ); + final Root from = query.from( UserEntity.class ); + final Subquery subquery = query.subquery( Long.class ); + final Path id = subquery.from( UserEntity.class ).get( "id" ); + query.where( from.get( "id" ).in( subquery.select( id ).where( cb.equal( id, 1L ) ) ) ); + executeQuery( session.createQuery( query ) ); + } ); + } + private void executeQuery(TypedQuery query) { final UserEntity result = query.getSingleResult(); assertThat( result.getId() ).isEqualTo( 1L );