From 6d15c1d1152975b34e912a85f5ad360e8e48c874 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Tue, 10 Jan 2023 10:10:18 +0100 Subject: [PATCH] HHH-15647 Add test for issue --- .../test/hql/HqlSubselectParameterTest.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/hql/HqlSubselectParameterTest.java 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; + + } +}