@@ -109,7 +109,8 @@ public enum Kind {
109109 // in-flight info
110110
111111 private Class <? extends UserType <?>> explicitCustomType ;
112- private Map <String ,String > explicitLocalTypeParams ;
112+ private Map <String ,String > explicitLocalCustomTypeParams ;
113+ private Annotation explicitCustomTypeAnnotation ;
113114
114115 private Function <TypeConfiguration , JdbcType > explicitJdbcTypeAccess ;
115116 private Function <TypeConfiguration , BasicJavaType > explicitJavaTypeAccess ;
@@ -324,30 +325,33 @@ public void setType(
324325 isLob = value .hasDirectAnnotationUsage ( Lob .class );
325326 }
326327
328+ final SourceModelBuildingContext context = getSourceModelContext ();
329+
327330 if ( getDialect ().getNationalizationSupport () == NationalizationSupport .EXPLICIT ) {
328331 isNationalized = buildingContext .getBuildingOptions ().useNationalizedCharacterData ()
329- || value .locateAnnotationUsage ( Nationalized .class , getSourceModelContext () ) != null ;
332+ || value .locateAnnotationUsage ( Nationalized .class , context ) != null ;
330333 }
331334
332335 if ( converterDescriptor != null ) {
333336 applyJpaConverter ( value , converterDescriptor );
334337 }
335338
336339 final Class <? extends UserType <?>> userTypeImpl =
337- kind .mappingAccess .customType ( value , getSourceModelContext () );
340+ kind .mappingAccess .customType ( value , context );
338341 if ( userTypeImpl != null ) {
339- applyExplicitType ( userTypeImpl ,
340- kind .mappingAccess .customTypeParameters ( value , getSourceModelContext () ) );
342+ this .explicitCustomType = userTypeImpl ;
343+ this .explicitLocalCustomTypeParams = kind .mappingAccess .customTypeParameters ( value , context );
344+ this .explicitCustomTypeAnnotation = kind .mappingAccess .customTypeAnnotation ( value , context );
341345 // An explicit custom UserType has top precedence when we get to BasicValue resolution.
342346 return ;
343347 }
344348 else if ( modelClassDetails != null ) {
345- final ClassDetails rawClassDetails = modelClassDetails .determineRawClass ();
346- final Class <?> basicClass = rawClassDetails .toJavaClass ();
347349 final Class <? extends UserType <?>> registeredUserTypeImpl =
348- getMetadataCollector ().findRegisteredUserType ( basicClass );
350+ getMetadataCollector ()
351+ .findRegisteredUserType ( modelClassDetails .determineRawClass ().toJavaClass () );
349352 if ( registeredUserTypeImpl != null ) {
350- applyExplicitType ( registeredUserTypeImpl , emptyMap () );
353+ this .explicitCustomType = registeredUserTypeImpl ;
354+ this .explicitLocalCustomTypeParams = emptyMap ();
351355 return ;
352356 }
353357 }
@@ -380,11 +384,6 @@ else if ( modelClassDetails != null ) {
380384
381385 }
382386
383- private void applyExplicitType (Class <? extends UserType <?>> impl , Map <String ,String > params ) {
384- this .explicitCustomType = impl ;
385- this .explicitLocalTypeParams = params ;
386- }
387-
388387 private void prepareCollectionId (MemberDetails attribute ) {
389388 final CollectionId collectionIdAnn = attribute .getDirectAnnotationUsage ( CollectionId .class );
390389 if ( collectionIdAnn == null ) {
@@ -1277,7 +1276,7 @@ else if ( aggregateComponent != null ) {
12771276 }
12781277
12791278 public void fillSimpleValue () {
1280- basicValue .setExplicitTypeParams ( explicitLocalTypeParams );
1279+ basicValue .setExplicitTypeParams ( explicitLocalCustomTypeParams );
12811280
12821281 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12831282 // todo (6.0) : we are dropping support for @Type and @TypeDef from annotations
@@ -1293,6 +1292,10 @@ public void fillSimpleValue() {
12931292 basicValue .setTypeParameters ( createDynamicParameterizedTypeParameters () );
12941293 }
12951294
1295+ if ( explicitCustomType != null ) {
1296+ basicValue .setTypeAnnotation ( explicitCustomTypeAnnotation );
1297+ }
1298+
12961299 if ( converterDescriptor != null ) {
12971300 basicValue .setJpaAttributeConverterDescriptor ( converterDescriptor );
12981301 }
@@ -1364,8 +1367,8 @@ private Map<String, Object> createDynamicParameterizedTypeParameters() {
13641367 parameters .put ( DynamicParameterizedType .ACCESS_TYPE , accessType .getType () );
13651368 }
13661369
1367- if ( explicitLocalTypeParams != null ) {
1368- parameters .putAll ( explicitLocalTypeParams );
1370+ if ( explicitLocalCustomTypeParams != null ) {
1371+ parameters .putAll ( explicitLocalCustomTypeParams );
13691372 }
13701373
13711374 return parameters ;
@@ -1377,6 +1380,7 @@ private Map<String, Object> createDynamicParameterizedTypeParameters() {
13771380 private interface BasicMappingAccess {
13781381 Class <? extends UserType <?>> customType (MemberDetails attribute , SourceModelBuildingContext context );
13791382 Map <String ,String > customTypeParameters (MemberDetails attribute , SourceModelBuildingContext context );
1383+ Annotation customTypeAnnotation (MemberDetails attribute , SourceModelBuildingContext context );
13801384 }
13811385
13821386 private static class ValueMappingAccess implements BasicMappingAccess {
@@ -1393,6 +1397,12 @@ public Map<String,String> customTypeParameters(MemberDetails attribute, SourceMo
13931397 final Type customType = attribute .locateAnnotationUsage ( Type .class , context );
13941398 return customType == null ? null : extractParameterMap ( customType .parameters () );
13951399 }
1400+
1401+ @ Override
1402+ public Annotation customTypeAnnotation (MemberDetails attribute , SourceModelBuildingContext context ) {
1403+ final List <? extends Annotation > metaAnnotated = attribute .getMetaAnnotated ( Type .class , context );
1404+ return metaAnnotated .size () == 1 ? metaAnnotated .get ( 0 ) : null ;
1405+ }
13961406 }
13971407
13981408 private static class AnyDiscriminatorMappingAccess implements BasicMappingAccess {
@@ -1407,6 +1417,11 @@ public Class<? extends UserType<?>> customType(MemberDetails attribute, SourceMo
14071417 public Map <String ,String > customTypeParameters (MemberDetails attribute , SourceModelBuildingContext context ) {
14081418 return emptyMap ();
14091419 }
1420+
1421+ @ Override
1422+ public Annotation customTypeAnnotation (MemberDetails attribute , SourceModelBuildingContext context ) {
1423+ return null ;
1424+ }
14101425 }
14111426
14121427 private static class AnyKeyMappingAccess implements BasicMappingAccess {
@@ -1421,6 +1436,11 @@ public Class<? extends UserType<?>> customType(MemberDetails attribute, SourceMo
14211436 public Map <String ,String > customTypeParameters (MemberDetails attribute , SourceModelBuildingContext context ) {
14221437 return emptyMap ();
14231438 }
1439+
1440+ @ Override
1441+ public Annotation customTypeAnnotation (MemberDetails attribute , SourceModelBuildingContext context ) {
1442+ return null ;
1443+ }
14241444 }
14251445
14261446 private static class MapKeyMappingAccess implements BasicMappingAccess {
@@ -1439,6 +1459,12 @@ public Map<String,String> customTypeParameters(MemberDetails attribute, SourceMo
14391459 return customType == null ? null : extractParameterMap ( customType .parameters () );
14401460
14411461 }
1462+
1463+ @ Override
1464+ public Annotation customTypeAnnotation (MemberDetails attribute , SourceModelBuildingContext context ) {
1465+ final List <? extends Annotation > metaAnnotated = attribute .getMetaAnnotated ( MapKeyType .class , context );
1466+ return metaAnnotated .size () == 1 ? metaAnnotated .get ( 0 ) : null ;
1467+ }
14421468 }
14431469
14441470 private static class CollectionIdMappingAccess implements BasicMappingAccess {
@@ -1455,7 +1481,12 @@ public Class<? extends UserType<?>> customType(MemberDetails attribute, SourceMo
14551481 public Map <String ,String > customTypeParameters (MemberDetails attribute , SourceModelBuildingContext context ) {
14561482 final CollectionIdType customType = attribute .locateAnnotationUsage ( CollectionIdType .class , context );
14571483 return customType == null ? null : extractParameterMap ( customType .parameters () );
1484+ }
14581485
1486+ @ Override
1487+ public Annotation customTypeAnnotation (MemberDetails attribute , SourceModelBuildingContext context ) {
1488+ final List <? extends Annotation > metaAnnotated = attribute .getMetaAnnotated ( CollectionIdType .class , context );
1489+ return metaAnnotated .size () == 1 ? metaAnnotated .get ( 0 ) : null ;
14591490 }
14601491 }
14611492
@@ -1471,6 +1502,11 @@ public Class<? extends UserType<?>> customType(MemberDetails attribute, SourceMo
14711502 public Map <String ,String > customTypeParameters (MemberDetails attribute , SourceModelBuildingContext context ) {
14721503 return emptyMap ();
14731504 }
1505+
1506+ @ Override
1507+ public Annotation customTypeAnnotation (MemberDetails attribute , SourceModelBuildingContext context ) {
1508+ return null ;
1509+ }
14741510 }
14751511
14761512 private static AnnotatedJoinColumns convertToJoinColumns (AnnotatedColumns columns , MetadataBuildingContext context ) {
0 commit comments