HHH-8935 MappedSuperclass can extend an Entity

This commit is contained in:
Brett Meyer 2014-02-05 00:36:23 -05:00
parent d8b669b951
commit a2971e4f75
3 changed files with 7 additions and 12 deletions

View File

@ -267,7 +267,7 @@ public class EntityHierarchyBuilder {
for ( ClassInfo subClassInfo : subClasses ) { for ( ClassInfo subClassInfo : subClasses ) {
if ( !isEntityClass( subClassInfo ) ) { if ( !isEntityClass( subClassInfo ) ) {
MappingAssertion.assertSubEntityIsNotEmbeddableNorMappedSuperclass( subClassInfo ); MappingAssertion.assertSubEntityIsNotEmbeddable( subClassInfo );
continue; continue;
} }
addSubClassToSubclassMap( classInfo.name(), subClassInfo, classToDirectSubclassMap ); addSubClassToSubclassMap( classInfo.name(), subClassInfo, classToDirectSubclassMap );

View File

@ -69,18 +69,14 @@ public class MappingAssertion {
/** /**
* Check if the sub-entity has {@link javax.persistence.Embeddable @Embeddable} or {@link javax.persistence.MappedSuperclass @MappedSuperclass}. * Check if the sub-entity has {@link javax.persistence.Embeddable @Embeddable}. From the JPA Spec,
* * a sub entity class can not has such annotation.
* From the JPA Spec, a sub entity class can not has such annotation.
* *
* @param subClassInfo The sub entity {@link ClassInfo class}. * @param subClassInfo The sub entity {@link ClassInfo class}.
*/ */
static void assertSubEntityIsNotEmbeddableNorMappedSuperclass(ClassInfo subClassInfo) { static void assertSubEntityIsNotEmbeddable(ClassInfo subClassInfo) {
if ( JandexHelper.containsSingleAnnotation( subClassInfo, JPADotNames.EMBEDDABLE ) ) { if ( JandexHelper.containsSingleAnnotation( subClassInfo, JPADotNames.EMBEDDABLE ) ) {
throw new AnnotationException( "An embeddable cannot extend an entity: " + subClassInfo ); throw new AnnotationException( "An embeddable cannot extend an entity: " + subClassInfo );
} }
if ( JandexHelper.containsSingleAnnotation( subClassInfo, JPADotNames.MAPPED_SUPERCLASS ) ) {
throw new AnnotationException( "A mapped superclass cannot extend an entity: " + subClassInfo );
}
} }
} }

View File

@ -23,24 +23,23 @@
*/ */
package org.hibernate.test.annotations.polymorphism; package org.hibernate.test.annotations.polymorphism;
import org.junit.Test; import static org.junit.Assert.assertEquals;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
* @author Brett Meyer * @author Brett Meyer
*/ */
@FailureExpectedWithNewMetamodel
public class PolymorphismTest extends BaseCoreFunctionalTestCase { public class PolymorphismTest extends BaseCoreFunctionalTestCase {
@Test @Test
@FailureExpectedWithNewMetamodel
public void testPolymorphism() throws Exception { public void testPolymorphism() throws Exception {
Car car = new Car(); Car car = new Car();
car.setModel( "SUV" ); car.setModel( "SUV" );