Skip to content

Commit

Permalink
HHH-18761 fix generation of named query method in presence of Jakarta…
Browse files Browse the repository at this point in the history
… Data

Signed-off-by: Gavin King <[email protected]>
  • Loading branch information
gavinking committed Oct 23, 2024
1 parent 93c18da commit 5223e84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
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;
Expand Down Expand Up @@ -107,7 +109,8 @@ private void handleNamedQuery(AnnotationMirror mirror, boolean checkHql) {
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(
Expand All @@ -121,13 +124,12 @@ private void handleNamedQuery(AnnotationMirror mirror, boolean checkHql) {
)
);
}
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 ) );
}
}
}
Expand Down Expand Up @@ -207,11 +209,11 @@ private NameMetaAttribute auxiliaryMember(AnnotationMirror mirror, String prefix
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 5223e84

Please sign in to comment.