HHH-18761 fix generation of named query method in presence of Jakarta Data

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-10-24 01:45:03 +02:00
parent bdc0070d97
commit fb7602a2e5
2 changed files with 11 additions and 6 deletions

View File

@ -26,8 +26,10 @@ import javax.lang.model.element.Element;
import java.util.List; import java.util.List;
import static java.lang.Character.isJavaIdentifierStart; 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.JAVA_OBJECT;
import static org.hibernate.processor.util.Constants.NAMED_QUERY; 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.containsAnnotation;
import static org.hibernate.processor.util.TypeUtils.getAnnotationMirror; import static org.hibernate.processor.util.TypeUtils.getAnnotationMirror;
import static org.hibernate.processor.util.TypeUtils.getAnnotationValue; import static org.hibernate.processor.util.TypeUtils.getAnnotationValue;
@ -107,7 +109,8 @@ public abstract class AnnotationMeta implements Metamodel {
ProcessorSessionFactory.create( context.getProcessingEnvironment(), ProcessorSessionFactory.create( context.getProcessingEnvironment(),
context.getEntityNameMappings(), context.getEnumTypesByValue() ) context.getEntityNameMappings(), context.getEnumTypesByValue() )
); );
if ( statement instanceof SqmSelectStatement<?> selectStatement ) { if ( !isJakartaDataStyle()
&& statement instanceof SqmSelectStatement<?> selectStatement ) {
if ( isQueryMethodName( name ) ) { if ( isQueryMethodName( name ) ) {
putMember( name, putMember( name,
new NamedQueryMethod( new NamedQueryMethod(
@ -121,13 +124,12 @@ public abstract class AnnotationMeta implements Metamodel {
) )
); );
} }
if ( !isJakartaDataStyle() if ( getAnnotationValue( mirror, "resultClass" ) == null ) {
&& getAnnotationValue( mirror, "resultClass" ) == null ) {
final String resultType = resultType( selectStatement ); final String resultType = resultType( selectStatement );
if ( resultType != null ) { if ( resultType != null ) {
putMember( "QUERY_" + name, putMember( "QUERY_" + name,
new TypedMetaAttribute( this, name, "QUERY_", resultType, 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 // and then we will replace this TypedMetaAttribute
return new TypedMetaAttribute( this, name, prefix, return new TypedMetaAttribute( this, name, prefix,
resultClass == null ? JAVA_OBJECT : resultClass.getValue().toString(), resultClass == null ? JAVA_OBJECT : resultClass.getValue().toString(),
"jakarta.persistence.TypedQueryReference", null ); TYPED_QUERY_REFERENCE, null );
} }
else if ( "GRAPH_".equals(prefix) ) { else if ( "GRAPH_".equals(prefix) ) {
return new TypedMetaAttribute( this, name, prefix, getQualifiedName(), return new TypedMetaAttribute( this, name, prefix, getQualifiedName(),
"jakarta.persistence.EntityGraph", null ); ENTITY_GRAPH, null );
} }
else { else {
return new NameMetaAttribute( this, name, prefix); return new NameMetaAttribute( this, name, prefix);

View File

@ -47,6 +47,9 @@ public final class Constants {
public static final String NAMED_ENTITY_GRAPH = "jakarta.persistence.NamedEntityGraph"; public static final String NAMED_ENTITY_GRAPH = "jakarta.persistence.NamedEntityGraph";
public static final String NAMED_ENTITY_GRAPHS = "jakarta.persistence.NamedEntityGraphs"; 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_QUERY = "org.hibernate.annotations.NamedQuery";
public static final String HIB_NAMED_QUERIES = "org.hibernate.annotations.NamedQueries"; public static final String HIB_NAMED_QUERIES = "org.hibernate.annotations.NamedQueries";
public static final String HIB_NAMED_NATIVE_QUERY = "org.hibernate.annotations.NamedNativeQuery"; public static final String HIB_NAMED_NATIVE_QUERY = "org.hibernate.annotations.NamedNativeQuery";