HHH-18761 add test

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-10-24 13:33:20 +02:00
parent fb7602a2e5
commit 743691e3b2
3 changed files with 46 additions and 0 deletions

View File

@ -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;
}

View File

@ -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_" );
}
}

View File

@ -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,