From af66aec4a1f4dd3a63793ee160c397aa6be4a1fd Mon Sep 17 00:00:00 2001 From: brmeyer Date: Tue, 6 Nov 2012 14:26:46 -0500 Subject: [PATCH] HHH-7761 @IdClass not working on mapped superclasses --- .../source/annotations/RootEntitySourceImpl.java | 14 ++++++++------ .../source/annotations/entity/RootEntityClass.java | 10 ++++++++++ .../hibernate/test/annotations/id/IdClassTest.java | 7 ++----- .../test/annotations/id/sequences/IdClassTest.java | 7 ++----- .../IdClassGeneratedValueTest.java | 3 ++- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/RootEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/RootEntitySourceImpl.java index 4f1e61c8b7..459c3d0a75 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/RootEntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/RootEntitySourceImpl.java @@ -58,6 +58,7 @@ import org.hibernate.metamodel.spi.source.VersionAttributeSource; /** * @author Hardy Ferentschik + * @author Brett Meyer */ public class RootEntitySourceImpl extends EntitySourceImpl implements RootEntitySource { private final RootEntityClass rootEntityClass; @@ -238,10 +239,10 @@ public class RootEntitySourceImpl extends EntitySourceImpl implements RootEntity @Override public Class getLookupIdClass() { - final AnnotationInstance idClassAnnotation = JandexHelper.getSingleAnnotation( - rootEntitySource.getEntityClass().getClassInfo(), - JPADotNames.ID_CLASS - ); + final AnnotationInstance idClassAnnotation = ( + ( RootEntityClass ) rootEntitySource.getEntityClass() ) + .getIdClassAnnotation(); + if ( idClassAnnotation == null ) { return null; } @@ -253,8 +254,9 @@ public class RootEntitySourceImpl extends EntitySourceImpl implements RootEntity @Override public String getIdClassPropertyAccessorName() { - // TODO: retrieve property accessor name for IdClass - return null; //To change body of implemented methods use File | Settings | File Templates. + // TODO: Should we retrieve property accessor name for the ID Class? + return rootEntitySource.getEntityClass().getClassAccessType().name() + .toLowerCase(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/RootEntityClass.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/RootEntityClass.java index f41ecbbd18..317ef33db8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/RootEntityClass.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/RootEntityClass.java @@ -48,6 +48,7 @@ import org.hibernate.metamodel.spi.binding.InheritanceType; * Represents an root entity configured via annotations/orm-xml. * * @author Hardy Ferentschik + * @author Brett Meyer */ public class RootEntityClass extends EntityClass { @@ -159,6 +160,15 @@ public class RootEntityClass extends EntityClass { return attributes; } + + public AnnotationInstance getIdClassAnnotation() { + // TODO: refactor + final List idClassAnnotations = findIdAnnotations( + JPADotNames.ID_CLASS + ); + + return ( idClassAnnotations.size() > 0 ) ? idClassAnnotations.get( 0 ) : null; + } private IdType determineIdType() { List idAnnotations = findIdAnnotations( JPADotNames.ID ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdClassTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdClassTest.java index 9968904c11..5797e6d3ec 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdClassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdClassTest.java @@ -23,22 +23,19 @@ */ package org.hibernate.test.annotations.id; -import org.junit.Test; +import static org.junit.Assert.assertNotNull; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.test.annotations.id.entities.Location; import org.hibernate.test.annotations.id.entities.Tower; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertNotNull; +import org.junit.Test; /** * @author Emmanuel Bernard */ @SuppressWarnings("unchecked") -@FailureExpectedWithNewMetamodel public class IdClassTest extends BaseCoreFunctionalTestCase { @Test public void testIdClassInSuperclass() throws Exception { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdClassTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdClassTest.java index d9727840b8..ddb29d8d70 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdClassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdClassTest.java @@ -23,22 +23,19 @@ */ package org.hibernate.test.annotations.id.sequences; -import org.junit.Test; +import static org.junit.Assert.assertNotNull; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.test.annotations.id.sequences.entities.Location; import org.hibernate.test.annotations.id.sequences.entities.Tower; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertNotNull; +import org.junit.Test; /** * @author Emmanuel Bernard */ @SuppressWarnings("unchecked") -@FailureExpectedWithNewMetamodel public class IdClassTest extends BaseCoreFunctionalTestCase { @Test public void testIdClassInSuperclass() throws Exception { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java index bc9314574b..fabf125791 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java @@ -39,7 +39,6 @@ import static org.junit.Assert.assertEquals; * * @author Stale W. Pedersen */ -@FailureExpectedWithNewMetamodel public class IdClassGeneratedValueTest extends BaseCoreFunctionalTestCase { @Test @SuppressWarnings({ "unchecked" }) @@ -67,6 +66,7 @@ public class IdClassGeneratedValueTest extends BaseCoreFunctionalTestCase { @Test @SuppressWarnings({ "unchecked" }) + @FailureExpectedWithNewMetamodel public void testSingleGeneratedValue() { Session s = openSession(); s.beginTransaction(); @@ -92,6 +92,7 @@ public class IdClassGeneratedValueTest extends BaseCoreFunctionalTestCase { @Test @SuppressWarnings({ "unchecked" }) + @FailureExpectedWithNewMetamodel public void testMultipleGeneratedValue() { Session s = openSession(); s.beginTransaction();