diff --git a/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/namedquery/Thing.java b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/namedquery/Thing.java new file mode 100644 index 0000000000..29abb05597 --- /dev/null +++ b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/namedquery/Thing.java @@ -0,0 +1,18 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.processor.test.namedquery; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.NamedQuery; + +@NamedQuery(name = "#things", + query = "from Thing where name like :name") +@Entity +public class Thing { + @Id @GeneratedValue long id; + String name; +} diff --git a/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/namedquery/ThingTest.java b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/namedquery/ThingTest.java new file mode 100644 index 0000000000..d22a8fd3df --- /dev/null +++ b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/namedquery/ThingTest.java @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.processor.test.namedquery; + +import jakarta.persistence.EntityManager; +import org.hibernate.processor.test.util.CompilationTest; +import org.hibernate.processor.test.util.WithClasses; +import org.junit.Test; + +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; +import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString; + +public class ThingTest extends CompilationTest { + @Test @WithClasses( Thing.class ) + public void test() { + System.out.println( getMetaModelSourceAsString( Thing.class) ); + System.out.println( getMetaModelSourceAsString( Thing.class, true) ); + assertMetamodelClassGeneratedFor(Thing.class); + assertMetamodelClassGeneratedFor(Thing.class, true); + assertPresenceOfMethodInMetamodelFor( Thing.class, "things", EntityManager.class, String.class ); + assertPresenceOfFieldInMetamodelFor( Thing.class, "__things_" ); + } +} diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMeta.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMeta.java index 56366ca0dd..beaacc8f78 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMeta.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMeta.java @@ -113,6 +113,7 @@ public abstract class AnnotationMeta implements Metamodel { && statement instanceof SqmSelectStatement selectStatement ) { if ( isQueryMethodName( name ) ) { putMember( name, + // TODO: respect @NamedQuery(resultClass) new NamedQueryMethod( this, selectStatement,