From e71f874e1fce510e943a38338e9d567008c3b70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Cedomir=20Igaly?= Date: Tue, 9 Jul 2024 10:13:19 +0200 Subject: [PATCH] HHH-18358 Test case - create metamodel from entity class containing named query comparing type(.) with literal --- .../test/typeliteral/TypeLiteralTest.java | 37 +++++++++++++++++++ .../processor/test/typeliteral/Simple.java | 17 +++++++++ 2 files changed, 54 insertions(+) create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/typeliteral/TypeLiteralTest.java create mode 100644 tooling/metamodel-generator/src/test/resources/org/hibernate/processor/test/typeliteral/Simple.java diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/typeliteral/TypeLiteralTest.java b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/typeliteral/TypeLiteralTest.java new file mode 100644 index 0000000000..62254f4912 --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/typeliteral/TypeLiteralTest.java @@ -0,0 +1,37 @@ +package org.hibernate.processor.test.typeliteral; + +import org.hibernate.processor.test.util.CompilationTest; +import org.hibernate.processor.test.util.TestForIssue; +import org.hibernate.processor.test.util.TestUtil; +import org.hibernate.processor.test.util.WithClasses; + +import org.junit.Test; + +import jakarta.persistence.EntityManager; + +import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor; +import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfFieldInMetamodelFor; +import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfMethodInMetamodelFor; + +public class TypeLiteralTest extends CompilationTest { + + @Test + @WithClasses( + value = {}, + sources = "org.hibernate.processor.test.typeliteral.Simple" + ) + @TestForIssue(jiraKey = "HHH-18358") + public void namedQueryWithTypeLiteral() { + final String entityClass = "org.hibernate.processor.test.typeliteral.Simple"; + + System.out.println( TestUtil.getMetaModelSourceAsString( entityClass ) ); + + assertMetamodelClassGeneratedFor( entityClass ); + + assertPresenceOfFieldInMetamodelFor( entityClass, "QUERY_SIMPLE" ); + assertPresenceOfFieldInMetamodelFor( entityClass, "QUERY_LONGER" ); + + assertPresenceOfMethodInMetamodelFor( entityClass, "simple", EntityManager.class ); + assertPresenceOfMethodInMetamodelFor( entityClass, "longer", EntityManager.class ); + } +} diff --git a/tooling/metamodel-generator/src/test/resources/org/hibernate/processor/test/typeliteral/Simple.java b/tooling/metamodel-generator/src/test/resources/org/hibernate/processor/test/typeliteral/Simple.java new file mode 100644 index 0000000000..61f0d62ae3 --- /dev/null +++ b/tooling/metamodel-generator/src/test/resources/org/hibernate/processor/test/typeliteral/Simple.java @@ -0,0 +1,17 @@ +package org.hibernate.processor.test.typeliteral; + +import org.hibernate.annotations.NamedQuery; +import org.hibernate.annotations.processing.CheckHQL; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; + +@Entity +@CheckHQL +@NamedQuery(name = "#simple", query = "select s from Simple s where type(s) = Simple") +@NamedQuery(name = "#longer", query = "select s from Simple s where type(s) = org.hibernate.processor.test.typeliteral.Simple") +public class Simple { + @Id + private Integer id; + private String value; +}