10
10
import java .util .List ;
11
11
import java .util .Set ;
12
12
import java .util .function .Consumer ;
13
+
13
14
import jakarta .persistence .metamodel .Bindable ;
14
15
import jakarta .persistence .metamodel .IdentifiableType ;
15
16
import jakarta .persistence .metamodel .SingularAttribute ;
26
27
import org .hibernate .metamodel .model .domain .SingularPersistentAttribute ;
27
28
import org .hibernate .metamodel .model .domain .spi .JpaMetamodelImplementor ;
28
29
import org .hibernate .query .sqm .SqmPathSource ;
30
+ import org .hibernate .query .sqm .tree .domain .SqmPersistentAttribute ;
29
31
import org .hibernate .query .sqm .tree .domain .SqmSingularPersistentAttribute ;
30
32
import org .hibernate .query .sqm .tree .domain .SqmEmbeddableDomainType ;
31
33
import org .hibernate .type .descriptor .java .JavaType ;
32
34
import org .hibernate .type .descriptor .java .spi .PrimitiveJavaType ;
33
35
34
36
import org .jboss .logging .Logger ;
35
37
36
- import static java .util .Collections .emptySet ;
38
+ import static java .util .Collections .emptyList ;
37
39
38
40
/**
39
41
* Functionality common to all implementations of {@link IdentifiableType}.
@@ -57,14 +59,14 @@ public abstract class AbstractIdentifiableType<J>
57
59
private final boolean hasIdClass ;
58
60
59
61
private SqmSingularPersistentAttribute <J ,?> id ;
60
- private Set < SingularPersistentAttribute <? super J ,?>> nonAggregatedIdAttributes ;
62
+ private List < SqmSingularPersistentAttribute <? super J ,?>> nonAggregatedIdAttributes ;
61
63
private SqmEmbeddableDomainType <?> idClassType ;
62
64
63
65
private SqmPathSource <?> identifierDescriptor ;
64
66
65
67
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 ;
68
70
69
71
public AbstractIdentifiableType (
70
72
String typeName ,
@@ -112,13 +114,13 @@ public IdentifiableDomainType<? super J> getSupertype() {
112
114
113
115
@ Override
114
116
@ SuppressWarnings ("unchecked" )
115
- public <Y > SingularPersistentAttribute <? super J , Y > getId (Class <Y > javaType ) {
117
+ public <Y > SqmSingularPersistentAttribute <? super J , Y > getId (Class <Y > javaType ) {
116
118
ensureNoIdClass ();
117
119
final var id = findIdAttribute ();
118
120
if ( id != null ) {
119
121
checkType ( id , javaType );
120
122
}
121
- return (SingularPersistentAttribute <? super J , Y >) id ;
123
+ return (SqmSingularPersistentAttribute <? super J , Y >) id ;
122
124
}
123
125
124
126
private void ensureNoIdClass () {
@@ -131,7 +133,7 @@ private void ensureNoIdClass() {
131
133
132
134
133
135
@ Override
134
- public SingularPersistentAttribute <? super J , ?> findIdAttribute () {
136
+ public SqmSingularPersistentAttribute <? super J , ?> findIdAttribute () {
135
137
if ( id != null ) {
136
138
return id ;
137
139
}
@@ -163,13 +165,13 @@ private void checkType(SingularPersistentAttribute<?, ?> attribute, Class<?> jav
163
165
164
166
@ Override
165
167
@ SuppressWarnings ("unchecked" )
166
- public <Y > SingularPersistentAttribute <J , Y > getDeclaredId (Class <Y > javaType ) {
168
+ public <Y > SqmSingularPersistentAttribute <J , Y > getDeclaredId (Class <Y > javaType ) {
167
169
ensureNoIdClass ();
168
170
if ( id == null ) {
169
171
throw new IllegalArgumentException ( "The id attribute is not declared on this type [" + getTypeName () + "]" );
170
172
}
171
173
checkType ( id , javaType );
172
- return (SingularPersistentAttribute <J , Y >) id ;
174
+ return (SqmSingularPersistentAttribute <J , Y >) id ;
173
175
}
174
176
175
177
@ Override
@@ -318,7 +320,7 @@ private void checkDeclaredVersion() {
318
320
*
319
321
* @return The declared
320
322
*/
321
- public SingularAttribute <J , ?> getDeclaredVersion () {
323
+ public SqmSingularPersistentAttribute <J , ?> getDeclaredVersion () {
322
324
checkDeclaredVersion ();
323
325
return versionAttribute ;
324
326
}
@@ -349,10 +351,12 @@ public void applyNonAggregatedIdAttributes(
349
351
}
350
352
351
353
if ( idAttributes .isEmpty () ) {
352
- nonAggregatedIdAttributes = emptySet ();
354
+ nonAggregatedIdAttributes = emptyList ();
353
355
}
354
356
else {
357
+ nonAggregatedIdAttributes = new ArrayList <>(idAttributes .size ());
355
358
for ( var idAttribute : idAttributes ) {
359
+ nonAggregatedIdAttributes .add ( (SqmSingularPersistentAttribute <? super J , ?>) idAttribute );
356
360
if ( AbstractIdentifiableType .this == idAttribute .getDeclaringType () ) {
357
361
@ SuppressWarnings ("unchecked" )
358
362
// Safe, because we know it's declared by this type
@@ -361,8 +365,6 @@ public void applyNonAggregatedIdAttributes(
361
365
addAttribute ( declaredAttribute );
362
366
}
363
367
}
364
-
365
- nonAggregatedIdAttributes = idAttributes ;
366
368
}
367
369
AbstractIdentifiableType .this .idClassType = (SqmEmbeddableDomainType <?>) idClassType ;
368
370
}
@@ -374,7 +376,8 @@ public void applyIdClassAttributes(Set<SingularPersistentAttribute<? super J, ?>
374
376
375
377
@ Override
376
378
public void applyVersionAttribute (SingularPersistentAttribute <J , ?> versionAttribute ) {
377
- AbstractIdentifiableType .this .versionAttribute = versionAttribute ;
379
+ AbstractIdentifiableType .this .versionAttribute =
380
+ (SqmSingularPersistentAttribute <J , ?>) versionAttribute ;
378
381
managedTypeAccess .addAttribute ( versionAttribute );
379
382
}
380
383
@@ -383,7 +386,7 @@ public void applyNaturalIdAttribute(PersistentAttribute<J, ?> naturalIdAttribute
383
386
if ( naturalIdAttributes == null ) {
384
387
naturalIdAttributes = new ArrayList <>();
385
388
}
386
- naturalIdAttributes .add ( naturalIdAttribute );
389
+ naturalIdAttributes .add ( ( SqmPersistentAttribute < J , ?>) naturalIdAttribute );
387
390
}
388
391
389
392
@ Override
0 commit comments