diff --git a/src/main/java/org/hibernate/models/internal/ArrayTypeDescriptor.java b/src/main/java/org/hibernate/models/internal/ArrayTypeDescriptor.java index 612a70b..da71ff3 100644 --- a/src/main/java/org/hibernate/models/internal/ArrayTypeDescriptor.java +++ b/src/main/java/org/hibernate/models/internal/ArrayTypeDescriptor.java @@ -7,6 +7,7 @@ package org.hibernate.models.internal; import java.lang.annotation.Annotation; +import java.lang.reflect.Array; import java.util.Collections; import java.util.List; @@ -32,6 +33,7 @@ */ public class ArrayTypeDescriptor implements ValueTypeDescriptor> { private final ValueTypeDescriptor elementTypeDescriptor; + private final Class componentType; private ValueWrapper, AnnotationValue> jandexValueWrapper; private ValueExtractor> jandexValueExtractor; @@ -39,8 +41,9 @@ public class ArrayTypeDescriptor implements ValueTypeDescriptor> { private ValueWrapper,Object[]> jdkValueWrapper; private ValueExtractor> jdkValueExtractor; - public ArrayTypeDescriptor(ValueTypeDescriptor elementTypeDescriptor) { + public ArrayTypeDescriptor(ValueTypeDescriptor elementTypeDescriptor, Class componentType) { this.elementTypeDescriptor = elementTypeDescriptor; + this.componentType = componentType; } @Override @@ -123,9 +126,9 @@ public ValueWrapper,Object[]> resolveJkWrapper(SourceModelBuildingContex @Override public Object unwrap(List value) { - final Object[] result = new Object[value.size()]; + final Object[] result = (Object[]) Array.newInstance( componentType, value.size() ); for ( int i = 0; i < value.size(); i++ ) { - result[i] = elementTypeDescriptor.unwrap( value.get(i) ); + result[i] = elementTypeDescriptor.unwrap( value.get( i ) ); } return result; } diff --git a/src/main/java/org/hibernate/models/internal/TypeDescriptors.java b/src/main/java/org/hibernate/models/internal/TypeDescriptors.java index 0c0564c..bb414d1 100644 --- a/src/main/java/org/hibernate/models/internal/TypeDescriptors.java +++ b/src/main/java/org/hibernate/models/internal/TypeDescriptors.java @@ -74,7 +74,7 @@ public static ValueTypeDescriptor resolveTypeDescriptor(Class attrib if ( attributeType.isArray() ) { final Class componentType = attributeType.getComponentType(); final ValueTypeDescriptor elementTypeDescriptor = resolveTypeDescriptor( componentType ); - return (ValueTypeDescriptor) new ArrayTypeDescriptor<>( elementTypeDescriptor ); + return (ValueTypeDescriptor) new ArrayTypeDescriptor<>( elementTypeDescriptor, componentType ); } if ( attributeType.isEnum() ) { diff --git a/src/test/java/org/hibernate/models/dynamic/ToAnnotationTest.java b/src/test/java/org/hibernate/models/dynamic/ToAnnotationTest.java new file mode 100644 index 0000000..9247d6b --- /dev/null +++ b/src/test/java/org/hibernate/models/dynamic/ToAnnotationTest.java @@ -0,0 +1,30 @@ +package org.hibernate.models.dynamic; + +import org.hibernate.models.internal.SourceModelBuildingContextImpl; +import org.hibernate.models.internal.dynamic.DynamicAnnotationUsage; +import org.hibernate.models.internal.dynamic.DynamicClassDetails; +import org.hibernate.models.orm.JpaAnnotations; + +import org.junit.jupiter.api.Test; + +import jakarta.persistence.JoinTable; + +import static org.hibernate.models.SourceModelTestHelper.createBuildingContext; + +public class ToAnnotationTest { + + @Test + void testAccessArrayOfAnnotations() { + final SourceModelBuildingContextImpl buildingContext = createBuildingContext(); + final DynamicClassDetails dynamicEntity = new DynamicClassDetails( "DynamicEntity", buildingContext ); + final DynamicAnnotationUsage generatorAnn = new DynamicAnnotationUsage<>( + JpaAnnotations.JOIN_TABLE, + dynamicEntity, + buildingContext + ); + + JoinTable joinTableAnn = generatorAnn.toAnnotation(); + + joinTableAnn.indexes(); + } +}