2525import static org .hibernate .processor .util .Constants .ENTITY_GRAPH ;
2626import static org .hibernate .processor .util .Constants .HIB_ENABLED_FETCH_PROFILE ;
2727import static org .hibernate .processor .util .Constants .JAVA_OBJECT ;
28+ import static org .hibernate .processor .util .Constants .NAMED_ENTITY_GRAPH ;
29+ import static org .hibernate .processor .util .Constants .NAMED_ENTITY_GRAPHS ;
2830import static org .hibernate .processor .util .Constants .NAMED_QUERY ;
2931import static org .hibernate .processor .util .Constants .TYPED_QUERY_REFERENCE ;
3032import static org .hibernate .processor .util .TypeUtils .containsAnnotation ;
@@ -42,7 +44,7 @@ void addAuxiliaryMembers() {
4244 addAuxiliaryMembersForAnnotation ( Constants .SQL_RESULT_SET_MAPPING , "MAPPING_" );
4345 addAuxiliaryMembersForRepeatableAnnotation ( Constants .SQL_RESULT_SET_MAPPINGS , "MAPPING_" );
4446 addAuxiliaryMembersForAnnotation ( Constants .NAMED_ENTITY_GRAPH , "GRAPH_" );
45- addAuxiliaryMembersForRepeatableAnnotation ( Constants . NAMED_ENTITY_GRAPHS , "GRAPH_" );
47+ addAuxiliaryMembersForRepeatableAnnotation ( NAMED_ENTITY_GRAPHS , "GRAPH_" );
4648
4749 addAuxiliaryMembersForAnnotation ( Constants .HIB_NAMED_QUERY , "QUERY_" );
4850 addAuxiliaryMembersForRepeatableAnnotation ( Constants .HIB_NAMED_QUERIES , "QUERY_" );
@@ -156,7 +158,7 @@ private void addAuxiliaryMembersForRepeatableAnnotation(String annotationName, S
156158 final List <? extends AnnotationValue > annotationValues =
157159 (List <? extends AnnotationValue >) value .getValue ();
158160 for ( AnnotationValue annotationValue : annotationValues ) {
159- addAuxiliaryMembersForMirror ( (AnnotationMirror ) annotationValue .getValue (), prefix );
161+ addAuxiliaryMembersForMirror ( (AnnotationMirror ) annotationValue .getValue (), prefix , annotationName );
160162 }
161163 }
162164 }
@@ -165,21 +167,32 @@ private void addAuxiliaryMembersForRepeatableAnnotation(String annotationName, S
165167 private void addAuxiliaryMembersForAnnotation (String annotationName , String prefix ) {
166168 final AnnotationMirror mirror = getAnnotationMirror ( getElement (), annotationName );
167169 if ( mirror != null ) {
168- addAuxiliaryMembersForMirror ( mirror , prefix );
170+ addAuxiliaryMembersForMirror ( mirror , prefix , annotationName );
169171 }
170172 }
171173
172- private void addAuxiliaryMembersForMirror (AnnotationMirror mirror , String prefix ) {
174+ private void addAuxiliaryMembersForMirror (AnnotationMirror mirror , String prefix , String annotationName ) {
173175 if ( !isJakartaDataStyle () ) {
174- mirror .getElementValues ().forEach ((key , value ) -> {
175- if ( key .getSimpleName ().contentEquals ("name" ) ) {
176- final String name = value .getValue ().toString ();
177- if ( !name .isEmpty () ) {
178- putMember ( prefix + name , auxiliaryMember ( mirror , prefix , name ) );
179- }
180- }
181- });
176+ final String name = defaultImplicitName ( annotationName , explicitName ( mirror ) );
177+ putMember ( prefix + name , auxiliaryMember ( mirror , prefix , name ) );
178+ }
179+ }
180+
181+ private static String explicitName (AnnotationMirror mirror ) {
182+ for ( var entry : mirror .getElementValues ().entrySet () ) {
183+ if ( entry .getKey ().getSimpleName ().contentEquals ( "name" ) ) {
184+ return entry .getValue ().getValue ().toString ();
185+ }
182186 }
187+ return "" ;
188+ }
189+
190+ private String defaultImplicitName (String annotationName , String explicitName ) {
191+ return explicitName .isEmpty ()
192+ && ( NAMED_ENTITY_GRAPH .equals ( annotationName )
193+ || NAMED_ENTITY_GRAPHS .equals ( annotationName ) )
194+ ? getSimpleName ()
195+ : explicitName ;
183196 }
184197
185198 private NameMetaAttribute auxiliaryMember (AnnotationMirror mirror , String prefix , String name ) {
0 commit comments