diff --git a/src/main/java/org/hibernate/models/internal/IsResolvedTypeSwitch.java b/src/main/java/org/hibernate/models/internal/IsResolvedTypeSwitch.java index 1819a0b..ad18a61 100644 --- a/src/main/java/org/hibernate/models/internal/IsResolvedTypeSwitch.java +++ b/src/main/java/org/hibernate/models/internal/IsResolvedTypeSwitch.java @@ -8,10 +8,8 @@ package org.hibernate.models.internal; import java.util.List; -import java.util.Objects; import org.hibernate.models.spi.ArrayTypeDetails; -import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassTypeDetails; import org.hibernate.models.spi.ParameterizedTypeDetails; import org.hibernate.models.spi.PrimitiveTypeDetails; @@ -63,7 +61,7 @@ public Boolean caseParameterizedType( SourceModelBuildingContext buildingContext) { final List typeArgs = parameterizedType.getArguments(); for ( TypeDetails arg : typeArgs ) { - if ( !isBound( arg, buildingContext ) ) { + if ( !arg.isResolved() ) { return false; } } diff --git a/src/test/java/org/hibernate/models/annotations/MapKeyTest.java b/src/test/java/org/hibernate/models/annotations/MapKeyTest.java new file mode 100644 index 0000000..f287264 --- /dev/null +++ b/src/test/java/org/hibernate/models/annotations/MapKeyTest.java @@ -0,0 +1,87 @@ +package org.hibernate.models.annotations; + +import java.util.Date; +import java.util.Map; + +import org.hibernate.models.SourceModelTestHelper; +import org.hibernate.models.internal.SourceModelBuildingContextImpl; +import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.FieldDetails; +import org.hibernate.models.spi.TypeDetails; + +import org.junit.jupiter.api.Test; + +import org.jboss.jandex.Index; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.MapKeyClass; +import jakarta.persistence.MapKeyColumn; +import jakarta.persistence.MapKeyTemporal; +import jakarta.persistence.OneToMany; +import jakarta.persistence.TemporalType; + +import static org.assertj.core.api.Assertions.assertThat; + +public class MapKeyTest { + + @Test + void testWithJandex() { + final Index index = SourceModelTestHelper.buildJandexIndex( + School.class, + Person.class + ); + testFieldsAreResolved( index ); + } + + @Test + void testWithoutJandex() { + testFieldsAreResolved( null ); + } + + void testFieldsAreResolved(Index index) { + final SourceModelBuildingContextImpl buildingContext = SourceModelTestHelper.createBuildingContext( + index, + School.class, + Person.class + ); + + final ClassDetails schoolClassDetails = buildingContext.getClassDetailsRegistry().getClassDetails( School.class.getName() ); + + final FieldDetails idField = schoolClassDetails.findFieldByName( "id" ); + final TypeDetails idFieldType = idField.getType(); + assertThat( idFieldType.isResolved() ).isTrue(); + + FieldDetails mapKeyField = schoolClassDetails.findFieldByName( "studentsByDate" ); + TypeDetails typeDetails = mapKeyField.resolveRelativeType( schoolClassDetails ); + assertThat( typeDetails.isResolved() ).isTrue(); + + FieldDetails mapKeyField2 = schoolClassDetails.findFieldByName( "teachersByDate" ); + TypeDetails typeDetails2 = mapKeyField2.resolveRelativeType( schoolClassDetails ); + assertThat( typeDetails2.isResolved() ).isFalse(); + } + + @Entity + public static class School { + @Id + private int id; + + @OneToMany(mappedBy = "school") + @MapKeyClass(Date.class) + @MapKeyColumn(name = "THE_DATE") + @MapKeyTemporal(TemporalType.DATE) + private Map studentsByDate; + + @OneToMany(mappedBy = "school") + @MapKeyClass(Date.class) + @MapKeyColumn(name = "THE_DATE") + @MapKeyTemporal(TemporalType.DATE) + private Map teachersByDate; + } + + @Entity + public static class Person { + @Id + private int id; + } +}