55package org .hibernate .boot .model ;
66
77import java .io .Serializable ;
8- import java .lang .annotation .Annotation ;
9- import java .lang .reflect .Constructor ;
10- import java .lang .reflect .InvocationTargetException ;
118import java .sql .Types ;
129import java .util .Arrays ;
13- import java .util .Collections ;
1410import java .util .Map ;
1511import java .util .Objects ;
1612import java .util .Properties ;
4238import org .hibernate .type .spi .TypeConfigurationAware ;
4339import org .hibernate .usertype .UserType ;
4440
41+ import static java .util .Collections .emptyMap ;
4542import static org .hibernate .boot .model .process .internal .InferredBasicValueResolver .resolveSqlTypeIndicators ;
4643import static org .hibernate .mapping .MappingHelper .injectParameters ;
4744
@@ -101,35 +98,32 @@ public Map<String,String> getParameters() {
10198
10299 public BasicValue .Resolution <?> resolve (
103100 Map <?,?> localConfigParameters ,
104- Annotation typeAnnotation ,
105101 MutabilityPlan <?> explicitMutabilityPlan ,
106102 MetadataBuildingContext context ,
107103 JdbcTypeIndicators indicators ) {
108104 if ( CollectionHelper .isEmpty ( localConfigParameters ) ) {
109105 // we can use the re-usable resolution...
110106 if ( reusableResolution == null ) {
111- reusableResolution = createResolution ( name , Collections . emptyMap (), typeAnnotation , indicators , context );
107+ reusableResolution = createResolution ( name , emptyMap (), indicators , context );
112108 }
113109 return reusableResolution ;
114110 }
115111 else {
116112 final String name = this .name + ":" + NAME_COUNTER .getAndIncrement ();
117- return createResolution ( name , localConfigParameters , typeAnnotation , indicators , context );
113+ return createResolution ( name , localConfigParameters , indicators , context );
118114 }
119115 }
120116
121117 private BasicValue .Resolution <?> createResolution (
122118 String name ,
123119 Map <?,?> usageSiteProperties ,
124- Annotation typeAnnotation ,
125120 JdbcTypeIndicators indicators ,
126121 MetadataBuildingContext context ) {
127122 return createResolution (
128123 name ,
129124 typeImplementorClass ,
130125 parameters ,
131126 usageSiteProperties ,
132- typeAnnotation ,
133127 indicators ,
134128 context
135129 );
@@ -140,7 +134,6 @@ private static <T> BasicValue.Resolution<T> createResolution(
140134 Class <T > typeImplementorClass ,
141135 Map <?,?> parameters ,
142136 Map <?,?> usageSiteProperties ,
143- Annotation typeAnnotation ,
144137 JdbcTypeIndicators indicators ,
145138 MetadataBuildingContext context ) {
146139 final BootstrapContext bootstrapContext = context .getBootstrapContext ();
@@ -154,7 +147,8 @@ private static <T> BasicValue.Resolution<T> createResolution(
154147 if ( isKnownType ) {
155148
156149 final T typeInstance =
157- instantiateType ( name , typeImplementorClass , typeAnnotation , context , bootstrapContext );
150+ instantiateType ( bootstrapContext .getServiceRegistry (), context .getBuildingOptions (),
151+ name , typeImplementorClass , bootstrapContext .getCustomTypeProducer () );
158152
159153 if ( typeInstance instanceof TypeConfigurationAware configurationAware ) {
160154 configurationAware .setTypeConfiguration ( typeConfiguration );
@@ -174,7 +168,7 @@ private static <T> BasicValue.Resolution<T> createResolution(
174168 @ SuppressWarnings ("unchecked" )
175169 final UserType <T > userType = (UserType <T >) typeInstance ;
176170 final CustomType <T > customType = new CustomType <>( userType , typeConfiguration );
177- return new UserTypeResolution <>( customType , null , combinedTypeParameters , typeAnnotation );
171+ return new UserTypeResolution <>( customType , null , combinedTypeParameters );
178172 }
179173
180174 if ( typeInstance instanceof BasicType ) {
@@ -231,28 +225,6 @@ public MutabilityPlan<T> getMutabilityPlan() {
231225 return resolveLegacyCases ( typeImplementorClass , indicators , typeConfiguration );
232226 }
233227
234- private static <T > T instantiateType (
235- String name , Class <T > typeImplementorClass , Annotation typeAnnotation ,
236- MetadataBuildingContext context , BootstrapContext bootstrapContext ) {
237- if ( typeAnnotation != null ) {
238- // attempt to instantiate it with the annotation as a constructor argument
239- try {
240- final Constructor <T > constructor = typeImplementorClass .getConstructor ( typeAnnotation .annotationType () );
241- constructor .setAccessible ( true );
242- return constructor .newInstance ( typeAnnotation );
243- }
244- catch ( NoSuchMethodException ignored ) {
245- // no such constructor, instantiate it the old way
246- }
247- catch (InvocationTargetException |InstantiationException |IllegalAccessException e ) {
248- throw new org .hibernate .InstantiationException ( "Could not instantiate custom type" , typeImplementorClass , e );
249- }
250- }
251-
252- return instantiateType ( bootstrapContext .getServiceRegistry (), context .getBuildingOptions (),
253- name , typeImplementorClass , bootstrapContext .getCustomTypeProducer () );
254- }
255-
256228 private static <T > BasicValue .Resolution <T > resolveLegacyCases (
257229 Class <T > typeImplementorClass , JdbcTypeIndicators indicators , TypeConfiguration typeConfiguration ) {
258230 final BasicType <T > legacyType ;
@@ -345,14 +317,12 @@ public static BasicValue.Resolution<?> createLocalResolution(
345317 String name ,
346318 Class <?> typeImplementorClass ,
347319 Map <?,?> localTypeParams ,
348- Annotation typeAnnotation ,
349320 MetadataBuildingContext buildingContext ) {
350321 return createResolution (
351322 name + ':' + NAME_COUNTER .getAndIncrement (),
352323 typeImplementorClass ,
353324 localTypeParams ,
354325 null ,
355- typeAnnotation ,
356326 buildingContext .getBootstrapContext ().getTypeConfiguration ().getCurrentBaseSqlTypeIndicators (),
357327 buildingContext
358328 );
0 commit comments