1010import java .util .List ;
1111import java .util .Set ;
1212import java .util .function .Consumer ;
13+
1314import jakarta .persistence .metamodel .Bindable ;
1415import jakarta .persistence .metamodel .IdentifiableType ;
1516import jakarta .persistence .metamodel .SingularAttribute ;
2627import org .hibernate .metamodel .model .domain .SingularPersistentAttribute ;
2728import org .hibernate .metamodel .model .domain .spi .JpaMetamodelImplementor ;
2829import org .hibernate .query .sqm .SqmPathSource ;
30+ import org .hibernate .query .sqm .tree .domain .SqmPersistentAttribute ;
2931import org .hibernate .query .sqm .tree .domain .SqmSingularPersistentAttribute ;
3032import org .hibernate .query .sqm .tree .domain .SqmEmbeddableDomainType ;
3133import org .hibernate .type .descriptor .java .JavaType ;
3234import org .hibernate .type .descriptor .java .spi .PrimitiveJavaType ;
3335
3436import org .jboss .logging .Logger ;
3537
36- import static java .util .Collections .emptySet ;
38+ import static java .util .Collections .emptyList ;
3739
3840/**
3941 * Functionality common to all implementations of {@link IdentifiableType}.
@@ -57,14 +59,14 @@ public abstract class AbstractIdentifiableType<J>
5759 private final boolean hasIdClass ;
5860
5961 private SqmSingularPersistentAttribute <J ,?> id ;
60- private Set < SingularPersistentAttribute <? super J ,?>> nonAggregatedIdAttributes ;
62+ private List < SqmSingularPersistentAttribute <? super J ,?>> nonAggregatedIdAttributes ;
6163 private SqmEmbeddableDomainType <?> idClassType ;
6264
6365 private SqmPathSource <?> identifierDescriptor ;
6466
6567 private final boolean isVersioned ;
66- private SingularPersistentAttribute <J , ?> versionAttribute ;
67- private List <PersistentAttribute <J ,?>> naturalIdAttributes ;
68+ private SqmSingularPersistentAttribute <J , ?> versionAttribute ;
69+ private List <SqmPersistentAttribute <J ,?>> naturalIdAttributes ;
6870
6971 public AbstractIdentifiableType (
7072 String typeName ,
@@ -112,13 +114,13 @@ public IdentifiableDomainType<? super J> getSupertype() {
112114
113115 @ Override
114116 @ SuppressWarnings ("unchecked" )
115- public <Y > SingularPersistentAttribute <? super J , Y > getId (Class <Y > javaType ) {
117+ public <Y > SqmSingularPersistentAttribute <? super J , Y > getId (Class <Y > javaType ) {
116118 ensureNoIdClass ();
117119 final var id = findIdAttribute ();
118120 if ( id != null ) {
119121 checkType ( id , javaType );
120122 }
121- return (SingularPersistentAttribute <? super J , Y >) id ;
123+ return (SqmSingularPersistentAttribute <? super J , Y >) id ;
122124 }
123125
124126 private void ensureNoIdClass () {
@@ -131,7 +133,7 @@ private void ensureNoIdClass() {
131133
132134
133135 @ Override
134- public SingularPersistentAttribute <? super J , ?> findIdAttribute () {
136+ public SqmSingularPersistentAttribute <? super J , ?> findIdAttribute () {
135137 if ( id != null ) {
136138 return id ;
137139 }
@@ -163,13 +165,13 @@ private void checkType(SingularPersistentAttribute<?, ?> attribute, Class<?> jav
163165
164166 @ Override
165167 @ SuppressWarnings ("unchecked" )
166- public <Y > SingularPersistentAttribute <J , Y > getDeclaredId (Class <Y > javaType ) {
168+ public <Y > SqmSingularPersistentAttribute <J , Y > getDeclaredId (Class <Y > javaType ) {
167169 ensureNoIdClass ();
168170 if ( id == null ) {
169171 throw new IllegalArgumentException ( "The id attribute is not declared on this type [" + getTypeName () + "]" );
170172 }
171173 checkType ( id , javaType );
172- return (SingularPersistentAttribute <J , Y >) id ;
174+ return (SqmSingularPersistentAttribute <J , Y >) id ;
173175 }
174176
175177 @ Override
@@ -318,7 +320,7 @@ private void checkDeclaredVersion() {
318320 *
319321 * @return The declared
320322 */
321- public SingularAttribute <J , ?> getDeclaredVersion () {
323+ public SqmSingularPersistentAttribute <J , ?> getDeclaredVersion () {
322324 checkDeclaredVersion ();
323325 return versionAttribute ;
324326 }
@@ -349,10 +351,12 @@ public void applyNonAggregatedIdAttributes(
349351 }
350352
351353 if ( idAttributes .isEmpty () ) {
352- nonAggregatedIdAttributes = emptySet ();
354+ nonAggregatedIdAttributes = emptyList ();
353355 }
354356 else {
357+ nonAggregatedIdAttributes = new ArrayList <>(idAttributes .size ());
355358 for ( var idAttribute : idAttributes ) {
359+ nonAggregatedIdAttributes .add ( (SqmSingularPersistentAttribute <? super J , ?>) idAttribute );
356360 if ( AbstractIdentifiableType .this == idAttribute .getDeclaringType () ) {
357361 @ SuppressWarnings ("unchecked" )
358362 // Safe, because we know it's declared by this type
@@ -361,8 +365,6 @@ public void applyNonAggregatedIdAttributes(
361365 addAttribute ( declaredAttribute );
362366 }
363367 }
364-
365- nonAggregatedIdAttributes = idAttributes ;
366368 }
367369 AbstractIdentifiableType .this .idClassType = (SqmEmbeddableDomainType <?>) idClassType ;
368370 }
@@ -374,7 +376,8 @@ public void applyIdClassAttributes(Set<SingularPersistentAttribute<? super J, ?>
374376
375377 @ Override
376378 public void applyVersionAttribute (SingularPersistentAttribute <J , ?> versionAttribute ) {
377- AbstractIdentifiableType .this .versionAttribute = versionAttribute ;
379+ AbstractIdentifiableType .this .versionAttribute =
380+ (SqmSingularPersistentAttribute <J , ?>) versionAttribute ;
378381 managedTypeAccess .addAttribute ( versionAttribute );
379382 }
380383
@@ -383,7 +386,7 @@ public void applyNaturalIdAttribute(PersistentAttribute<J, ?> naturalIdAttribute
383386 if ( naturalIdAttributes == null ) {
384387 naturalIdAttributes = new ArrayList <>();
385388 }
386- naturalIdAttributes .add ( naturalIdAttribute );
389+ naturalIdAttributes .add ( ( SqmPersistentAttribute < J , ?>) naturalIdAttribute );
387390 }
388391
389392 @ Override
0 commit comments