From 4af03102e4bab9fb49a736be4c8233c3d7be3282 Mon Sep 17 00:00:00 2001 From: brmeyer Date: Tue, 4 Dec 2012 11:47:21 -0500 Subject: [PATCH] HHH-7762 Discriminators broken on abstract superclass with no @DiscriminatorValue --- .../hibernate/metamodel/internal/Binder.java | 7 +++++-- .../annotations/inheritance/SubclassTest.java | 17 +++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java index 974a685180..f6c28125e6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel.internal; import static org.hibernate.engine.spi.SyntheticAttributeHelper.SYNTHETIC_COMPOSITE_ID_ATTRIBUTE_NAME; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -75,9 +76,9 @@ import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor; import org.hibernate.metamodel.spi.binding.IdGenerator; import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.InheritanceType; +import org.hibernate.metamodel.spi.binding.ManyToManyPluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; import org.hibernate.metamodel.spi.binding.MetaAttribute; -import org.hibernate.metamodel.spi.binding.ManyToManyPluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.OneToManyPluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.OneToOneAttributeBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; @@ -802,7 +803,9 @@ public class Binder { if ( discriminatorValue != null ) { rootEntityBinding.setDiscriminatorMatchValue( discriminatorValue ); } - else { + else if ( !Modifier.isAbstract( bindingContext().locateClassByName( rootEntitySource.getEntityName() ).getModifiers() ) ) { + // Use the class name as a default if no dscriminator value. + // However, skip abstract classes -- obviously no discriminators there. rootEntityBinding.setDiscriminatorMatchValue( rootEntitySource.getEntityName() ); } // Configure discriminator hibernate type diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/SubclassTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/SubclassTest.java index c7d1bb5b6f..85adfbdc2e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/SubclassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/SubclassTest.java @@ -23,9 +23,13 @@ */ package org.hibernate.test.annotations.inheritance; -import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; -import org.junit.Test; +import java.util.List; import org.hibernate.Query; import org.hibernate.Session; @@ -37,19 +41,12 @@ import org.hibernate.test.annotations.inheritance.singletable.Funk; import org.hibernate.test.annotations.inheritance.singletable.Music; import org.hibernate.test.annotations.inheritance.singletable.Noise; import org.hibernate.test.annotations.inheritance.singletable.Rock; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import org.junit.Test; /** * @author Emmanuel Bernard */ -@FailureExpectedWithNewMetamodel public class SubclassTest extends BaseCoreFunctionalTestCase { @Override protected boolean isCleanupTestDataRequired() {