From 177ceaef15b314de06f5528d5067650c1d45bde2 Mon Sep 17 00:00:00 2001 From: Jan-Willem Gmelig Meyling Date: Tue, 11 Sep 2018 10:41:13 +0200 Subject: [PATCH] [HHH-12969] Identifiable.getJavaType() returns IdClass member type rather than Entity class member type --- .../IdClassAssociationMetamodelTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/metamodel/IdClassAssociationMetamodelTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/metamodel/IdClassAssociationMetamodelTest.java b/hibernate-core/src/test/java/org/hibernate/test/metamodel/IdClassAssociationMetamodelTest.java new file mode 100644 index 0000000000..01747b161d --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/metamodel/IdClassAssociationMetamodelTest.java @@ -0,0 +1,50 @@ +package org.hibernate.test.metamodel; + +import java.io.Serializable; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.ManyToOne; +import javax.persistence.metamodel.SingularAttribute; + +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; + +import org.junit.Test; + +import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; +import static org.junit.Assert.assertEquals; + +public class IdClassAssociationMetamodelTest extends BaseEntityManagerFunctionalTestCase { + + @Entity @IdClass(EntityType.EntityId.class) public static class EntityType { + @Id private Long key2; + @Id @ManyToOne + private SomeAssociationType key1; + + public static class EntityId implements Serializable { + private Long key1, key2; + } + } + + @Entity public static class SomeAssociationType { + @Id + private Long id; + } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { EntityType.class, SomeAssociationType.class }; + } + + @Test + public void idClassAttributeIsProperlyRepresentedInMetamodelTest() { + doInJPA( this::entityManagerFactory, entityManager -> { + javax.persistence.metamodel.EntityType entity = entityManager.getMetamodel() + .entity( EntityType.class ); + + SingularAttribute key1 = entity.getSingularAttribute( "key1" ); + assertEquals( SomeAssociationType.class, key1.getJavaType() ); + assertEquals( SomeAssociationType.class, key1.getType().getJavaType() ); + } ); + } +}