Skip to content

Commit

Permalink
Fix annotation ClassDetails default values extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 committed Mar 19, 2024
1 parent 12a6fc2 commit 5df2c12
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,15 @@ private static Object wrapValue(Object value, AnnotationTarget target, SourceMod
throw new AnnotationAccessException( "Error accessing default annotation attribute value", e );
}
}
else if ( value != null && value.getClass().isArray() ) {
return getList( value, target, context );
else if ( value != null ) {
if ( value.getClass().isArray() ) {
return getList( value, target, context );
}
else if ( value.getClass() == Class.class ) {
return context.getClassDetailsRegistry().findClassDetails( ( (Class) value ).getName() );
}
}

return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import org.hibernate.models.internal.dynamic.DynamicAnnotationUsage;
import org.hibernate.models.internal.dynamic.DynamicClassDetails;
import org.hibernate.models.orm.JpaAnnotations;
import org.hibernate.models.spi.ClassDetails;

import org.junit.jupiter.api.Test;

import jakarta.persistence.ConstraintMode;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.JoinTable;
Expand Down Expand Up @@ -110,4 +112,18 @@ void testDefaultValues() {
String generator = generatorAnn.findAttributeValue( "generator" );
assertThat( generator ).isEqualTo( "" );
}

@Test
void testClassDetailsDefaultValue(){
final SourceModelBuildingContextImpl buildingContext = createBuildingContext();
final DynamicClassDetails dynamicEntity = new DynamicClassDetails( "DynamicEntity", buildingContext );
final DynamicAnnotationUsage<ElementCollection> elementCollectionAnn = new DynamicAnnotationUsage<>(
JpaAnnotations.ELEMENT_COLLECTION,
dynamicEntity,
buildingContext
);

Object value = elementCollectionAnn.getAttributeValue( "targetClass" );
assertThat( value ).isInstanceOf( ClassDetails.class );
}
}

0 comments on commit 5df2c12

Please sign in to comment.