36
36
import org .hibernate .type .descriptor .java .SerializableJavaType ;
37
37
import org .hibernate .type .descriptor .java .TemporalJavaType ;
38
38
import org .hibernate .type .descriptor .java .spi .JavaTypeRegistry ;
39
+ import org .hibernate .type .descriptor .java .spi .JdbcTypeRecommendationException ;
39
40
import org .hibernate .type .descriptor .jdbc .JdbcType ;
40
41
import org .hibernate .type .descriptor .jdbc .JdbcTypeIndicators ;
41
42
import org .hibernate .type .descriptor .jdbc .ObjectJdbcType ;
@@ -74,9 +75,10 @@ public static <T> BasicValue.Resolution<T> from(
74
75
75
76
final JavaType <T > reflectedJtd = reflectedJtdResolver .get ();
76
77
77
- // NOTE : the distinction that is made below wrt `explicitJavaType` and `reflectedJtd` is
78
- // needed temporarily to trigger "legacy resolution" versus "ORM6 resolution. Yes, it
79
- // makes the code a little more complicated but the benefit is well worth it - saving memory
78
+ // NOTE: the distinction that is made below wrt `explicitJavaType` and `reflectedJtd`
79
+ // is needed temporarily to trigger "legacy resolution" versus "ORM6 resolution.
80
+ // Yes, it makes the code a little more complicated but the benefit is well worth
81
+ // it - saving memory
80
82
81
83
final BasicType <T > jdbcMapping ;
82
84
@@ -141,8 +143,8 @@ else if ( explicitJdbcType != null ) {
141
143
);
142
144
}
143
145
else {
144
- // see if there is a registered BasicType for this JavaType and, if so, use it.
145
- // this mimics the legacy handling
146
+ // see if there is a registered BasicType for this JavaType and,
147
+ // if so, use it. This mimics the legacy handling.
146
148
final BasicType registeredType ;
147
149
if ( reflectedJtd instanceof BasicPluralJavaType <?> ) {
148
150
final BasicPluralJavaType <?> containerJtd = (BasicPluralJavaType <?>) reflectedJtd ;
@@ -198,9 +200,26 @@ else if ( isTemporal( elementJtd ) ) {
198
200
jdbcMapping = resolveSqlTypeIndicators ( stdIndicators , registeredType , reflectedJtd );
199
201
}
200
202
else {
201
- // there was not a "legacy" BasicType registration, so use `JavaType#getRecommendedJdbcType`, if
202
- // one, to create a mapping
203
- final JdbcType recommendedJdbcType = reflectedJtd .getRecommendedJdbcType ( stdIndicators );
203
+ // there was not a "legacy" BasicType registration,
204
+ // so use `JavaType#getRecommendedJdbcType`, if one,
205
+ // to create a mapping
206
+ final JdbcType recommendedJdbcType ;
207
+ try {
208
+ recommendedJdbcType = reflectedJtd .getRecommendedJdbcType ( stdIndicators );
209
+ }
210
+ catch (JdbcTypeRecommendationException jtre ) {
211
+ if ( buildingContext .getMetadataCollector ()
212
+ .getEntityBindingMap ().values ().stream ()
213
+ .anyMatch ( pc -> pc .getMappedClass ().equals (resolvedJavaType ) ) ) {
214
+ throw new MappingException ( "Incorrect use of entity type '"
215
+ + resolvedJavaType .getTypeName ()
216
+ + "' (possibly due to missing association mapping annotation)" ,
217
+ jtre );
218
+ }
219
+ else {
220
+ throw jtre ;
221
+ }
222
+ }
204
223
if ( recommendedJdbcType != null ) {
205
224
jdbcMapping = resolveSqlTypeIndicators (
206
225
stdIndicators ,
@@ -222,7 +241,7 @@ else if ( reflectedJtd instanceof SerializableJavaType
222
241
else {
223
242
if ( explicitJdbcType != null ) {
224
243
// we have an explicit STD, but no JTD - infer JTD
225
- // - NOTE : yes its an odd case, but its easy to implement here, so...
244
+ // NOTE : yes it's an odd case, but easy to implement here, so...
226
245
Integer length = null ;
227
246
Integer scale = null ;
228
247
if ( selectable instanceof Column ) {
@@ -251,7 +270,6 @@ else if ( column.getLength() != null ) {
251
270
}
252
271
else {
253
272
// we have neither a JTD nor STD
254
-
255
273
throw new MappingException (
256
274
"Could not determine JavaType nor JdbcType to use" +
257
275
" for BasicValue: owner = " + ownerName +
0 commit comments