From 5b11014c7caffd294fa671b257f8fbd41340a67b Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Thu, 28 Feb 2019 08:29:40 +0200 Subject: [PATCH] HHH-13217 - Don't throw exception if both @MappedSuperclass and @Inheritance are used Make sure the @Inheritance annotation is ignored when used along with @MappedSuperclass --- .../MappedSuperclassInheritanceTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/test/inheritance/MappedSuperclassInheritanceTest.java b/hibernate-core/src/test/java/org/hibernate/test/inheritance/MappedSuperclassInheritanceTest.java index 969e1100fa..4093d24ee3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/inheritance/MappedSuperclassInheritanceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/inheritance/MappedSuperclassInheritanceTest.java @@ -14,17 +14,20 @@ import javax.persistence.InheritanceType; import javax.persistence.MappedSuperclass; import org.hibernate.cfg.AnnotationBinder; +import org.hibernate.hql.internal.ast.QuerySyntaxException; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.logger.LoggerInspectionRule; import org.hibernate.testing.logger.Triggerable; +import org.hibernate.testing.util.ExceptionUtil; import org.junit.Rule; import org.junit.Test; import org.jboss.logging.Logger; +import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -62,7 +65,18 @@ public class MappedSuperclassInheritanceTest extends BaseEntityManagerFunctional @Test public void test() { + doInJPA( this::entityManagerFactory, entityManager -> { + entityManager.createQuery("from Manager").getResultList(); + entityManager.createQuery("from Developer").getResultList(); + try { + //Check the @Inheritance annotation was ignored + entityManager.createQuery("from Employee").getResultList(); + } catch (Exception expected) { + QuerySyntaxException rootException = (QuerySyntaxException) ExceptionUtil.rootCause(expected); + assertEquals("Employee is not mapped", rootException.getMessage()); + } + } ); } @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)