Skip to content

Commit fb7602a

Browse files
committed
HHH-18761 fix generation of named query method in presence of Jakarta Data
Signed-off-by: Gavin King <[email protected]>
1 parent bdc0070 commit fb7602a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMeta.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import java.util.List;
2727

2828
import static java.lang.Character.isJavaIdentifierStart;
29+
import static org.hibernate.processor.util.Constants.ENTITY_GRAPH;
2930
import static org.hibernate.processor.util.Constants.JAVA_OBJECT;
3031
import static org.hibernate.processor.util.Constants.NAMED_QUERY;
32+
import static org.hibernate.processor.util.Constants.TYPED_QUERY_REFERENCE;
3133
import static org.hibernate.processor.util.TypeUtils.containsAnnotation;
3234
import static org.hibernate.processor.util.TypeUtils.getAnnotationMirror;
3335
import static org.hibernate.processor.util.TypeUtils.getAnnotationValue;
@@ -107,7 +109,8 @@ private void handleNamedQuery(AnnotationMirror mirror, boolean checkHql) {
107109
ProcessorSessionFactory.create( context.getProcessingEnvironment(),
108110
context.getEntityNameMappings(), context.getEnumTypesByValue() )
109111
);
110-
if ( statement instanceof SqmSelectStatement<?> selectStatement ) {
112+
if ( !isJakartaDataStyle()
113+
&& statement instanceof SqmSelectStatement<?> selectStatement ) {
111114
if ( isQueryMethodName( name ) ) {
112115
putMember( name,
113116
new NamedQueryMethod(
@@ -121,13 +124,12 @@ private void handleNamedQuery(AnnotationMirror mirror, boolean checkHql) {
121124
)
122125
);
123126
}
124-
if ( !isJakartaDataStyle()
125-
&& getAnnotationValue( mirror, "resultClass" ) == null ) {
127+
if ( getAnnotationValue( mirror, "resultClass" ) == null ) {
126128
final String resultType = resultType( selectStatement );
127129
if ( resultType != null ) {
128130
putMember( "QUERY_" + name,
129131
new TypedMetaAttribute( this, name, "QUERY_", resultType,
130-
"jakarta.persistence.TypedQueryReference", hql ) );
132+
TYPED_QUERY_REFERENCE, hql ) );
131133
}
132134
}
133135
}
@@ -207,11 +209,11 @@ private NameMetaAttribute auxiliaryMember(AnnotationMirror mirror, String prefix
207209
// and then we will replace this TypedMetaAttribute
208210
return new TypedMetaAttribute( this, name, prefix,
209211
resultClass == null ? JAVA_OBJECT : resultClass.getValue().toString(),
210-
"jakarta.persistence.TypedQueryReference", null );
212+
TYPED_QUERY_REFERENCE, null );
211213
}
212214
else if ( "GRAPH_".equals(prefix) ) {
213215
return new TypedMetaAttribute( this, name, prefix, getQualifiedName(),
214-
"jakarta.persistence.EntityGraph", null );
216+
ENTITY_GRAPH, null );
215217
}
216218
else {
217219
return new NameMetaAttribute( this, name, prefix);

tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public final class Constants {
4747
public static final String NAMED_ENTITY_GRAPH = "jakarta.persistence.NamedEntityGraph";
4848
public static final String NAMED_ENTITY_GRAPHS = "jakarta.persistence.NamedEntityGraphs";
4949

50+
public static final String TYPED_QUERY_REFERENCE = "jakarta.persistence.TypedQueryReference";
51+
public static final String ENTITY_GRAPH = "jakarta.persistence.EntityGraph";
52+
5053
public static final String HIB_NAMED_QUERY = "org.hibernate.annotations.NamedQuery";
5154
public static final String HIB_NAMED_QUERIES = "org.hibernate.annotations.NamedQueries";
5255
public static final String HIB_NAMED_NATIVE_QUERY = "org.hibernate.annotations.NamedNativeQuery";

0 commit comments

Comments
 (0)