From 78e6d632f25e3800b1e80a55c386b295ca339c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Cedomir=20Igaly?= Date: Thu, 28 Nov 2024 18:24:17 +0100 Subject: [PATCH] HHH-18894 Simplified test case selecting (non-managed) enum constant as column --- .../query/SelectUnknownEnumLiteralTest.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/query/SelectUnknownEnumLiteralTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/SelectUnknownEnumLiteralTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/SelectUnknownEnumLiteralTest.java new file mode 100644 index 0000000000..c5629d0a49 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/SelectUnknownEnumLiteralTest.java @@ -0,0 +1,64 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.query; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Tuple; +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.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@DomainModel(annotatedClasses = SelectUnknownEnumLiteralTest.Transaction.class) +@SessionFactory +public class SelectUnknownEnumLiteralTest { + + @BeforeAll + void setup(SessionFactoryScope scope) { + scope.inTransaction( em -> em.persist( new Transaction( 1L, "abc" ) ) ); + } + + @AfterAll + void clean(SessionFactoryScope scope) { + scope.inTransaction( em -> em.createMutationQuery( "delete from Tx" ).executeUpdate() ); + } + + @Test + void test(SessionFactoryScope scope) { + final List tuples = scope.fromSession( em -> + em.createQuery( + "SELECT org.hibernate.orm.test.query.SelectUnknownEnumLiteralTest$Type.TRANSACTION, e.id, e.reference FROM Tx e", + Tuple.class ).getResultList() ); + assertEquals( 1, tuples.size() ); + assertEquals( Type.TRANSACTION, tuples.get( 0 ).get( 0 ) ); + assertEquals( 1L, tuples.get( 0 ).get( 1 ) ); + } + + @Entity(name = "Tx") + static class Transaction { + @Id + Long id; + String reference; + + Transaction() { + } + + Transaction(Long id, String reference) { + this.id = id; + this.reference = reference; + } + } + + enum Type { + TRANSACTION, DIRECT_DEBIT_GROUP, DIRECT_DEBIT + } +}