From fb7602a2e587a98eeba3c4d1304ac4faed550746 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Thu, 24 Oct 2024 01:45:03 +0200 Subject: [PATCH] HHH-18761 fix generation of named query method in presence of Jakarta Data Signed-off-by: Gavin King --- .../processor/annotation/AnnotationMeta.java | 14 ++++++++------ .../org/hibernate/processor/util/Constants.java | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) 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 05a3b65505..56366ca0dd 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 @@ -26,8 +26,10 @@ import javax.lang.model.element.Element; import java.util.List; import static java.lang.Character.isJavaIdentifierStart; +import static org.hibernate.processor.util.Constants.ENTITY_GRAPH; import static org.hibernate.processor.util.Constants.JAVA_OBJECT; import static org.hibernate.processor.util.Constants.NAMED_QUERY; +import static org.hibernate.processor.util.Constants.TYPED_QUERY_REFERENCE; import static org.hibernate.processor.util.TypeUtils.containsAnnotation; import static org.hibernate.processor.util.TypeUtils.getAnnotationMirror; import static org.hibernate.processor.util.TypeUtils.getAnnotationValue; @@ -107,7 +109,8 @@ public abstract class AnnotationMeta implements Metamodel { ProcessorSessionFactory.create( context.getProcessingEnvironment(), context.getEntityNameMappings(), context.getEnumTypesByValue() ) ); - if ( statement instanceof SqmSelectStatement selectStatement ) { + if ( !isJakartaDataStyle() + && statement instanceof SqmSelectStatement selectStatement ) { if ( isQueryMethodName( name ) ) { putMember( name, new NamedQueryMethod( @@ -121,13 +124,12 @@ public abstract class AnnotationMeta implements Metamodel { ) ); } - if ( !isJakartaDataStyle() - && getAnnotationValue( mirror, "resultClass" ) == null ) { + if ( getAnnotationValue( mirror, "resultClass" ) == null ) { final String resultType = resultType( selectStatement ); if ( resultType != null ) { putMember( "QUERY_" + name, new TypedMetaAttribute( this, name, "QUERY_", resultType, - "jakarta.persistence.TypedQueryReference", hql ) ); + TYPED_QUERY_REFERENCE, hql ) ); } } } @@ -207,11 +209,11 @@ public abstract class AnnotationMeta implements Metamodel { // and then we will replace this TypedMetaAttribute return new TypedMetaAttribute( this, name, prefix, resultClass == null ? JAVA_OBJECT : resultClass.getValue().toString(), - "jakarta.persistence.TypedQueryReference", null ); + TYPED_QUERY_REFERENCE, null ); } else if ( "GRAPH_".equals(prefix) ) { return new TypedMetaAttribute( this, name, prefix, getQualifiedName(), - "jakarta.persistence.EntityGraph", null ); + ENTITY_GRAPH, null ); } else { return new NameMetaAttribute( this, name, prefix); diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java index 9cd84c04fb..8d93474d47 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java @@ -47,6 +47,9 @@ public final class Constants { public static final String NAMED_ENTITY_GRAPH = "jakarta.persistence.NamedEntityGraph"; public static final String NAMED_ENTITY_GRAPHS = "jakarta.persistence.NamedEntityGraphs"; + public static final String TYPED_QUERY_REFERENCE = "jakarta.persistence.TypedQueryReference"; + public static final String ENTITY_GRAPH = "jakarta.persistence.EntityGraph"; + public static final String HIB_NAMED_QUERY = "org.hibernate.annotations.NamedQuery"; public static final String HIB_NAMED_QUERIES = "org.hibernate.annotations.NamedQueries"; public static final String HIB_NAMED_NATIVE_QUERY = "org.hibernate.annotations.NamedNativeQuery";