diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/JandexHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/JandexHelper.java index cf48b624d3..1de6231813 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/JandexHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/JandexHelper.java @@ -123,6 +123,45 @@ public class JandexHelper { ); } } + + // THIS IS FOR 4.3.x AND SHOULD BE CONSIDERED TEMPORARY. HHH-8118 corrected CL use in JandexHelper by adding + // CLS as method arguments. But that was done in the metamodel branch only before I knew that master added a few + // uses. HHH-8316 needs it for 4.3. DO NOT LET THIS GET MERGED INTO METAMODEL! + public static T getValue(AnnotationInstance annotation, String element, Class type, + ClassLoaderService classLoaderService) throws AssertionFailure { + if ( Class.class.equals( type ) ) { + throw new AssertionFailure( + "Annotation parameters of type Class should be retrieved as strings (fully qualified class names)" + ); + } + + if ( type.isPrimitive() ) { + type = PrimitiveWrapperHelper.getDescriptorByPrimitiveType( type ).getWrapperClass(); + } + + // try getting the untyped value from Jandex + AnnotationValue annotationValue = annotation.value( element ); + + try { + if ( annotationValue != null ) { + return explicitAnnotationParameter( annotationValue, type ); + } + else { + return defaultAnnotationParameter( getDefaultValue( annotation, element, classLoaderService ), type ); + } + } + catch ( ClassCastException e ) { + throw new AssertionFailure( + String.format( + "the annotation property %s of annotation %s is not of type %s", + element, + annotation.name(), + type.getName() + ), + e + ); + } + } /** * Retrieves a jandex annotation element value, converting it to the supplied enumerated type. If the value is @@ -332,6 +371,39 @@ public class JandexHelper { } } + // THIS IS FOR 4.3.x AND SHOULD BE CONSIDERED TEMPORARY. HHH-8118 corrected CL use in JandexHelper by adding + // CLS as method arguments. But that was done in the metamodel branch only before I knew that master added a few + // uses. HHH-8316 needs it for 4.3. DO NOT LET THIS GET MERGED INTO METAMODEL! + private static Object getDefaultValue(AnnotationInstance annotation, String element, + ClassLoaderService classLoaderService) { + String name = annotation.name().toString(); + String fqElement = name + '.' + element; + Object val = DEFAULT_VALUES_BY_ELEMENT.get( fqElement ); + if ( val != null ) { + return val; + } + try { + val = classLoaderService.classForName( name ).getMethod( element ).getDefaultValue(); + if ( val != null ) { + // Annotation parameters of type Class are handled using Strings + if ( val instanceof Class ) { + val = ( ( Class ) val ).getName(); + } + } + DEFAULT_VALUES_BY_ELEMENT.put( fqElement, val ); + return val; + } + catch ( RuntimeException error ) { + throw error; + } + catch ( Exception error ) { + throw new AssertionFailure( + String.format( "The annotation %s does not define a parameter '%s'", name, element ), + error + ); + } + } + private static T defaultAnnotationParameter(Object defaultValue, Class type) { Object returnValue = defaultValue; diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java index eb3fe79eba..d2f297aee0 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java @@ -391,7 +391,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil metadataSources.converterDescriptors.add( new MetadataSources.ConverterDescriptor( className, - JandexHelper.getValue( converterAnnotation, "autoApply", boolean.class ) + JandexHelper.getValue( converterAnnotation, "autoApply", boolean.class, + bootstrapServiceRegistry.getService( ClassLoaderService.class ) ) ) ); }