diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/hql/HqlSubselectParameterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/HqlSubselectParameterTest.java new file mode 100644 index 0000000000..02e6562e1a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/HqlSubselectParameterTest.java @@ -0,0 +1,89 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.orm.test.hql; + +import java.util.List; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@DomainModel( + annotatedClasses = { + HqlSubselectParameterTest.Resource.class, + HqlSubselectParameterTest.Bookmark.class + } +) +@SessionFactory +@TestForIssue(jiraKey = "HHH-15647") +public class HqlSubselectParameterTest { + + @BeforeAll + public void setUp(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + Resource resource = new Resource(); + session.persist( resource ); + Bookmark bookmark = new Bookmark(); + session.persist( bookmark ); + + } + ); + } + + @Test + public void testHqlQuery(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + String query = "select rsrc, (select count(mrk.key) from bookmark as mrk where mrk.key=:identityKey) as myBookmarks from resource as rsrc"; + List objects = session.createQuery( query, Object[].class ) + .setParameter( "identityKey", 100l ) + .getResultList(); + + assertThat( objects.size() ).isEqualTo( 1 ); + } + ); + } + + @Entity(name = "bookmark") + @Table(name = "o_bookmark") + public static class Bookmark { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false, unique = true, updatable = false) + private Long key; + + private String name; + + } + + @Entity(name = "resource") + @Table(name = "o_resource") + public static class Resource { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false, unique = true, updatable = false) + private Long key; + + private String name; + + } +}