4
4
*/
5
5
package org .hibernate .boot .models .xml .internal .attr ;
6
6
7
- import java .util .List ;
8
-
7
+ import jakarta .persistence .AccessType ;
8
+ import jakarta .persistence .DiscriminatorType ;
9
+ import jakarta .persistence .JoinColumn ;
9
10
import org .hibernate .annotations .AnyDiscriminatorValue ;
10
- import org .hibernate .boot .jaxb .mapping .spi .JaxbAnyDiscriminatorValueMappingImpl ;
11
- import org .hibernate .boot .jaxb .mapping .spi .JaxbAnyMappingDiscriminatorImpl ;
11
+ import org .hibernate .boot .jaxb .mapping .spi .JaxbAnyMapping ;
12
12
import org .hibernate .boot .jaxb .mapping .spi .JaxbAnyMappingImpl ;
13
- import org .hibernate .boot .jaxb .mapping .spi .JaxbAnyMappingKeyImpl ;
14
13
import org .hibernate .boot .jaxb .mapping .spi .JaxbColumnImpl ;
14
+ import org .hibernate .boot .jaxb .mapping .spi .JaxbDiscriminatorMapping ;
15
15
import org .hibernate .boot .models .HibernateAnnotations ;
16
16
import org .hibernate .boot .models .JpaAnnotations ;
17
17
import org .hibernate .boot .models .annotations .internal .AnyAnnotation ;
18
18
import org .hibernate .boot .models .annotations .internal .AnyDiscriminatorAnnotation ;
19
19
import org .hibernate .boot .models .annotations .internal .AnyDiscriminatorValueAnnotation ;
20
20
import org .hibernate .boot .models .annotations .internal .AnyDiscriminatorValuesAnnotation ;
21
21
import org .hibernate .boot .models .annotations .internal .AnyKeTypeAnnotation ;
22
+ import org .hibernate .boot .models .annotations .internal .AnyKeyJavaClassAnnotation ;
22
23
import org .hibernate .boot .models .annotations .internal .ColumnJpaAnnotation ;
23
24
import org .hibernate .boot .models .annotations .internal .JoinColumnJpaAnnotation ;
24
25
import org .hibernate .boot .models .annotations .internal .JoinColumnsJpaAnnotation ;
26
+ import org .hibernate .boot .models .xml .internal .SimpleTypeInterpretation ;
25
27
import org .hibernate .boot .models .xml .internal .XmlAnnotationHelper ;
26
28
import org .hibernate .boot .models .xml .internal .XmlProcessingHelper ;
27
29
import org .hibernate .boot .models .xml .spi .XmlDocumentContext ;
31
33
import org .hibernate .models .spi .MutableClassDetails ;
32
34
import org .hibernate .models .spi .MutableMemberDetails ;
33
35
34
- import jakarta .persistence .AccessType ;
35
- import jakarta .persistence .DiscriminatorType ;
36
- import jakarta .persistence .JoinColumn ;
36
+ import java .util .List ;
37
37
38
38
import static org .hibernate .boot .models .HibernateAnnotations .ANY_DISCRIMINATOR_VALUE ;
39
39
import static org .hibernate .boot .models .JpaAnnotations .JOIN_COLUMN ;
40
- import static org .hibernate .boot .models .xml .internal .attr .CommonAttributeProcessing .*;
41
40
import static org .hibernate .boot .models .xml .internal .attr .CommonAttributeProcessing .applyAccess ;
42
41
import static org .hibernate .boot .models .xml .internal .attr .CommonAttributeProcessing .applyAttributeAccessor ;
42
+ import static org .hibernate .boot .models .xml .internal .attr .CommonAttributeProcessing .applyFetching ;
43
+ import static org .hibernate .boot .models .xml .internal .attr .CommonAttributeProcessing .applyOptimisticLock ;
44
+ import static org .hibernate .boot .models .xml .internal .attr .CommonAttributeProcessing .applyOptionality ;
43
45
import static org .hibernate .internal .util .NullnessHelper .coalesce ;
44
46
45
47
/**
@@ -77,11 +79,11 @@ public static MutableMemberDetails processAnyMappingAttribute(
77
79
return memberDetails ;
78
80
}
79
81
80
- private static void applyDiscriminator (
82
+ static void applyDiscriminator (
81
83
MutableMemberDetails memberDetails ,
82
- JaxbAnyMappingImpl jaxbHbmAnyMapping ,
84
+ JaxbAnyMapping jaxbHbmAnyMapping ,
83
85
XmlDocumentContext xmlDocumentContext ) {
84
- final JaxbAnyMappingDiscriminatorImpl jaxbDiscriminator = jaxbHbmAnyMapping .getDiscriminator ();
86
+ final JaxbAnyMapping . Discriminator jaxbDiscriminator = jaxbHbmAnyMapping .getDiscriminator ();
85
87
final AnyDiscriminatorAnnotation anyDiscriminatorAnn = (AnyDiscriminatorAnnotation ) memberDetails .applyAnnotationUsage (
86
88
HibernateAnnotations .ANY_DISCRIMINATOR ,
87
89
xmlDocumentContext .getModelBuildingContext ()
@@ -105,7 +107,7 @@ private static void applyDiscriminator(
105
107
columnAnn .apply ( jaxbColumn , xmlDocumentContext );
106
108
}
107
109
108
- final List <JaxbAnyDiscriminatorValueMappingImpl > jaxbValueMappings = jaxbDiscriminator .getValueMappings ();
110
+ final List <? extends JaxbDiscriminatorMapping > jaxbValueMappings = jaxbDiscriminator .getValueMappings ();
109
111
if ( CollectionHelper .isNotEmpty ( jaxbValueMappings ) ) {
110
112
final AnyDiscriminatorValuesAnnotation discriminatorValuesUsage = (AnyDiscriminatorValuesAnnotation ) memberDetails .replaceAnnotationUsage (
111
113
ANY_DISCRIMINATOR_VALUE ,
@@ -120,14 +122,14 @@ private static void applyDiscriminator(
120
122
}
121
123
122
124
private static AnyDiscriminatorValue [] collectDiscriminatorValues (
123
- List <JaxbAnyDiscriminatorValueMappingImpl > jaxbValueMappings ,
125
+ List <? extends JaxbDiscriminatorMapping > jaxbValueMappings ,
124
126
XmlDocumentContext xmlDocumentContext ) {
125
127
final AnyDiscriminatorValue [] values = new AnyDiscriminatorValue [jaxbValueMappings .size ()];
126
128
for ( int i = 0 ; i < jaxbValueMappings .size (); i ++ ) {
127
129
final AnyDiscriminatorValueAnnotation valueAnn = ANY_DISCRIMINATOR_VALUE .createUsage ( xmlDocumentContext .getModelBuildingContext () );
128
130
values [i ] = valueAnn ;
129
131
130
- final JaxbAnyDiscriminatorValueMappingImpl jaxbValue = jaxbValueMappings .get ( i );
132
+ final JaxbDiscriminatorMapping jaxbValue = jaxbValueMappings .get ( i );
131
133
132
134
valueAnn .discriminator ( jaxbValue .getDiscriminatorValue () );
133
135
@@ -141,18 +143,25 @@ private static AnyDiscriminatorValue[] collectDiscriminatorValues(
141
143
return values ;
142
144
}
143
145
144
- private static void applyKey (
146
+ static void applyKey (
145
147
MutableMemberDetails memberDetails ,
146
- JaxbAnyMappingImpl jaxbHbmAnyMapping ,
148
+ JaxbAnyMapping jaxbHbmAnyMapping ,
147
149
XmlDocumentContext xmlDocumentContext ) {
148
- final JaxbAnyMappingKeyImpl jaxbKey = jaxbHbmAnyMapping .getKey ();
150
+ final JaxbAnyMapping . Key jaxbKey = jaxbHbmAnyMapping .getKey ();
149
151
if ( StringHelper .isNotEmpty ( jaxbKey .getType () ) ) {
150
152
final AnyKeTypeAnnotation keyTypeUsage = (AnyKeTypeAnnotation ) memberDetails .applyAnnotationUsage (
151
153
HibernateAnnotations .ANY_KEY_TYPE ,
152
154
xmlDocumentContext .getModelBuildingContext ()
153
155
);
154
156
keyTypeUsage .value ( jaxbKey .getType () );
155
157
}
158
+ else if ( StringHelper .isNotEmpty ( jaxbKey .getJavaClass () ) ) {
159
+ final AnyKeyJavaClassAnnotation keyJavaType = (AnyKeyJavaClassAnnotation ) memberDetails .applyAnnotationUsage (
160
+ HibernateAnnotations .ANY_KEY_JAVA_CLASS ,
161
+ xmlDocumentContext .getModelBuildingContext ()
162
+ );
163
+ keyJavaType .value ( resolveKeyType ( jaxbKey .getJavaClass (), xmlDocumentContext ) );
164
+ }
156
165
157
166
if ( jaxbKey .getColumns ().isEmpty () ) {
158
167
memberDetails .applyAnnotationUsage ( JpaAnnotations .JOIN_COLUMN , xmlDocumentContext .getModelBuildingContext () );
@@ -177,4 +186,17 @@ private static void applyKey(
177
186
}
178
187
}
179
188
189
+ private static Class <?> resolveKeyType (String name , XmlDocumentContext xmlDocumentContext ) {
190
+ final SimpleTypeInterpretation simpleTypeInterpretation = SimpleTypeInterpretation .interpret ( name );
191
+ if ( simpleTypeInterpretation != null ) {
192
+ return simpleTypeInterpretation .getJavaType ();
193
+ }
194
+
195
+ return xmlDocumentContext
196
+ .getBootstrapContext ()
197
+ .getModelsContext ()
198
+ .getClassLoading ()
199
+ .classForName ( xmlDocumentContext .resolveClassName ( name ) );
200
+ }
201
+
180
202
}
0 commit comments