12
12
import java .util .function .Supplier ;
13
13
14
14
import org .hibernate .MappingException ;
15
+ import org .hibernate .boot .spi .BootstrapContext ;
15
16
import org .hibernate .boot .spi .MetadataBuildingContext ;
16
17
import org .hibernate .dialect .Dialect ;
17
18
import org .hibernate .mapping .BasicValue ;
@@ -60,7 +61,8 @@ public static <T> BasicValue.Resolution<T> from(
60
61
String propertyName ,
61
62
MetadataBuildingContext buildingContext ) {
62
63
final Dialect dialect = buildingContext .getMetadataCollector ().getDatabase ().getDialect ();
63
- final TypeConfiguration typeConfiguration = buildingContext .getBootstrapContext ().getTypeConfiguration ();
64
+ final BootstrapContext bootstrapContext = buildingContext .getBootstrapContext ();
65
+ final TypeConfiguration typeConfiguration = bootstrapContext .getTypeConfiguration ();
64
66
65
67
final JavaType <T > reflectedJtd = reflectedJtdResolver .get ();
66
68
@@ -70,16 +72,15 @@ public static <T> BasicValue.Resolution<T> from(
70
72
71
73
final BasicType <T > jdbcMapping ;
72
74
73
- if ( explicitJavaType != null ) {
75
+ if (explicitJavaType != null ) {
74
76
// we have an explicit JavaType
75
77
if ( isTemporal ( explicitJavaType ) ) {
76
78
return fromTemporal (
77
79
(TemporalJavaType <T >) explicitJavaType ,
78
80
null ,
79
81
explicitJdbcType ,
80
82
explicitMutabilityPlanAccess ,
81
- stdIndicators ,
82
- typeConfiguration
83
+ stdIndicators
83
84
);
84
85
}
85
86
else if ( explicitJdbcType != null ) {
@@ -116,7 +117,8 @@ else if ( reflectedJtd != null ) {
116
117
return fromEnum (
117
118
(EnumJavaType ) reflectedJtd ,
118
119
null ,
119
- stdIndicators
120
+ stdIndicators ,
121
+ bootstrapContext
120
122
);
121
123
}
122
124
else if ( isTemporal ( reflectedJtd ) ) {
@@ -125,8 +127,7 @@ else if ( isTemporal( reflectedJtd ) ) {
125
127
null ,
126
128
explicitJdbcType ,
127
129
explicitMutabilityPlanAccess ,
128
- stdIndicators ,
129
- typeConfiguration
130
+ stdIndicators
130
131
);
131
132
}
132
133
else if ( explicitJdbcType != null ) {
@@ -148,8 +149,8 @@ else if ( explicitJdbcType != null ) {
148
149
final BasicValue .Resolution <?> resolution = fromEnum (
149
150
(EnumJavaType <?>) elementJtd ,
150
151
null ,
151
- stdIndicators
152
- );
152
+ stdIndicators ,
153
+ bootstrapContext );
153
154
registeredElementType = (BasicType <?>) resolution .getJdbcMapping ();
154
155
}
155
156
else if ( isTemporal ( elementJtd ) ) {
@@ -158,8 +159,7 @@ else if ( isTemporal( elementJtd ) ) {
158
159
null ,
159
160
null ,
160
161
explicitMutabilityPlanAccess ,
161
- stdIndicators ,
162
- typeConfiguration
162
+ stdIndicators
163
163
);
164
164
registeredElementType = resolution .getLegacyResolvedBasicType ();
165
165
}
@@ -305,17 +305,19 @@ public static <T> BasicType<T> resolveSqlTypeIndicators(
305
305
public static <E extends Enum <E >> BasicValue .Resolution <E > fromEnum (
306
306
EnumJavaType <E > enumJavaType ,
307
307
JdbcType explicitJdbcType ,
308
- JdbcTypeIndicators stdIndicators ) {
308
+ JdbcTypeIndicators stdIndicators ,
309
+ BootstrapContext bootstrapContext ) {
309
310
final JdbcType jdbcType = explicitJdbcType == null
310
- ? enumJavaType .getRecommendedJdbcType ( stdIndicators )
311
+ ? enumJavaType .getRecommendedJdbcType (stdIndicators )
311
312
: explicitJdbcType ;
312
- final BasicType <E > jdbcMapping = new BasicTypeImpl <>( enumJavaType , jdbcType );
313
+ final BasicTypeImpl <E > basicType = new BasicTypeImpl <>(enumJavaType , jdbcType );
314
+ bootstrapContext .registerAdHocBasicType (basicType );
313
315
return new InferredBasicValueResolution <>(
314
- jdbcMapping ,
316
+ basicType ,
315
317
enumJavaType ,
316
318
enumJavaType ,
317
319
jdbcType ,
318
- jdbcMapping ,
320
+ basicType ,
319
321
ImmutableMutabilityPlan .instance ()
320
322
);
321
323
}
@@ -325,15 +327,15 @@ public static <T> BasicValue.Resolution<T> fromTemporal(
325
327
BasicJavaType <?> explicitJavaType ,
326
328
JdbcType explicitJdbcType ,
327
329
Function <TypeConfiguration , MutabilityPlan > explicitMutabilityPlanAccess ,
328
- JdbcTypeIndicators stdIndicators ,
329
- TypeConfiguration typeConfiguration ) {
330
+ JdbcTypeIndicators stdIndicators ) {
331
+ final TypeConfiguration typeConfiguration = stdIndicators . getTypeConfiguration ();
330
332
final TemporalType requestedTemporalPrecision = stdIndicators .getTemporalPrecision ();
331
333
332
334
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
333
335
// Case #1 - explicit JavaType
334
336
335
- if ( explicitJavaType != null ) {
336
- if ( !isTemporal ( explicitJavaType ) ) {
337
+ if (explicitJavaType != null ) {
338
+ if (!isTemporal (explicitJavaType ) ) {
337
339
throw new MappingException (
338
340
"Explicit JavaType [" + explicitJavaType +
339
341
"] defined for temporal value must implement TemporalJavaType"
@@ -342,7 +344,6 @@ public static <T> BasicValue.Resolution<T> fromTemporal(
342
344
343
345
@ SuppressWarnings ("unchecked" )
344
346
final TemporalJavaType <T > explicitTemporalJtd = (TemporalJavaType <T >) explicitJavaType ;
345
-
346
347
if ( requestedTemporalPrecision != null && explicitTemporalJtd .getPrecision () != requestedTemporalPrecision ) {
347
348
throw new MappingException (
348
349
"Temporal precision (`jakarta.persistence.TemporalType`) mismatch... requested precision = " + requestedTemporalPrecision +
@@ -354,9 +355,7 @@ public static <T> BasicValue.Resolution<T> fromTemporal(
354
355
final JdbcType jdbcType = explicitJdbcType != null
355
356
? explicitJdbcType
356
357
: explicitTemporalJtd .getRecommendedJdbcType ( stdIndicators );
357
-
358
358
final BasicType <T > jdbcMapping = typeConfiguration .getBasicTypeRegistry ().resolve ( explicitTemporalJtd , jdbcType );
359
-
360
359
final MutabilityPlan <T > mutabilityPlan = determineMutabilityPlan ( explicitMutabilityPlanAccess , explicitTemporalJtd , typeConfiguration );
361
360
return new InferredBasicValueResolution <>(
362
361
jdbcMapping ,
0 commit comments