Skip to content

Commit 4af0310

Browse files
committed
HHH-7762 Discriminators broken on abstract superclass with no
@DiscriminatorValue
1 parent 51e7504 commit 4af0310

File tree

2 files changed

+12
-12
lines changed
  • hibernate-core/src

2 files changed

+12
-12
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import static org.hibernate.engine.spi.SyntheticAttributeHelper.SYNTHETIC_COMPOSITE_ID_ATTRIBUTE_NAME;
2727

28+
import java.lang.reflect.Modifier;
2829
import java.util.ArrayList;
2930
import java.util.Comparator;
3031
import java.util.HashMap;
@@ -75,9 +76,9 @@
7576
import org.hibernate.metamodel.spi.binding.IdGenerator;
7677
import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding;
7778
import org.hibernate.metamodel.spi.binding.InheritanceType;
79+
import org.hibernate.metamodel.spi.binding.ManyToManyPluralAttributeElementBinding;
7880
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
7981
import org.hibernate.metamodel.spi.binding.MetaAttribute;
80-
import org.hibernate.metamodel.spi.binding.ManyToManyPluralAttributeElementBinding;
8182
import org.hibernate.metamodel.spi.binding.OneToManyPluralAttributeElementBinding;
8283
import org.hibernate.metamodel.spi.binding.OneToOneAttributeBinding;
8384
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
@@ -802,7 +803,9 @@ private void bindDiscriminator( final EntityBinding rootEntityBinding, final Roo
802803
if ( discriminatorValue != null ) {
803804
rootEntityBinding.setDiscriminatorMatchValue( discriminatorValue );
804805
}
805-
else {
806+
else if ( !Modifier.isAbstract( bindingContext().locateClassByName( rootEntitySource.getEntityName() ).getModifiers() ) ) {
807+
// Use the class name as a default if no dscriminator value.
808+
// However, skip abstract classes -- obviously no discriminators there.
806809
rootEntityBinding.setDiscriminatorMatchValue( rootEntitySource.getEntityName() );
807810
}
808811
// Configure discriminator hibernate type

hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/SubclassTest.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@
2323
*/
2424
package org.hibernate.test.annotations.inheritance;
2525

26-
import java.util.List;
26+
import static org.junit.Assert.assertEquals;
27+
import static org.junit.Assert.assertFalse;
28+
import static org.junit.Assert.assertNotNull;
29+
import static org.junit.Assert.assertNull;
30+
import static org.junit.Assert.assertTrue;
2731

28-
import org.junit.Test;
32+
import java.util.List;
2933

3034
import org.hibernate.Query;
3135
import org.hibernate.Session;
@@ -37,19 +41,12 @@
3741
import org.hibernate.test.annotations.inheritance.singletable.Music;
3842
import org.hibernate.test.annotations.inheritance.singletable.Noise;
3943
import org.hibernate.test.annotations.inheritance.singletable.Rock;
40-
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
4144
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
42-
43-
import static org.junit.Assert.assertEquals;
44-
import static org.junit.Assert.assertFalse;
45-
import static org.junit.Assert.assertNotNull;
46-
import static org.junit.Assert.assertNull;
47-
import static org.junit.Assert.assertTrue;
45+
import org.junit.Test;
4846

4947
/**
5048
* @author Emmanuel Bernard
5149
*/
52-
@FailureExpectedWithNewMetamodel
5350
public class SubclassTest extends BaseCoreFunctionalTestCase {
5451
@Override
5552
protected boolean isCleanupTestDataRequired() {

0 commit comments

Comments
 (0)