HHH-13217 - Don't throw exception if both @MappedSuperclass and @Inheritance are used

This commit is contained in:
Vlad Mihalcea 2019-02-11 18:08:17 +02:00
parent 072d8ca315
commit 170007fc9a
3 changed files with 31 additions and 18 deletions

View File

@ -535,8 +535,7 @@ public final class AnnotationBinder {
if ( clazzToProcess.isAnnotationPresent( Inheritance.class )
&& clazzToProcess.isAnnotationPresent( MappedSuperclass.class ) ) {
throw new AnnotationException( "An entity cannot be annotated with both @Inheritance and @MappedSuperclass: "
+ clazzToProcess.getName() );
LOG.unsupportedMappedSuperclassWithEntityInheritance( clazzToProcess.getName() );
}
//TODO: be more strict with secondarytable allowance (not for ids, not for secondary table join columns etc)

View File

@ -1849,17 +1849,21 @@ public interface CoreMessageLogger extends BasicLogger {
@Message(value = "Using @AttributeOverride or @AttributeOverrides in conjunction with entity inheritance is not supported: %s. The overriding definitions are ignored.", id = 499)
void unsupportedAttributeOverrideWithEntityInheritance(String entityName);
/** 6.0 message loggers
@LogMessage(level = WARN)
@Message(value = "The bytecode provider class [%s] could not be loaded", id = 500)
void bytecodeProviderClassNotFound(String className);
/** 6.0 message loggers
@LogMessage(level = WARN)
@Message(value = "The bytecode provider class [%s] could not be loaded", id = 500)
void bytecodeProviderClassNotFound(String className);
@LogMessage(level = WARN)
@Message(value = "The bytecode provider class [%s] does not implement BytecodeProvider", id = 501)
void bytecodeProviderInvalidClass(String className);
*/
@LogMessage(level = WARN)
@Message(value = "The bytecode provider class [%s] does not implement BytecodeProvider", id = 501)
void bytecodeProviderInvalidClass(String className);
*/
@LogMessage(level = WARN)
@Message(value = "The [%s] property of the [%s] entity was modified, but it won't be updated because the property is immutable.", id = 502)
void ignoreImmutablePropertyModification(String propertyName, String entityName);
@LogMessage(level = WARN)
@Message(value = "An entity cannot be annotated with both @Inheritance and @MappedSuperclass: %s.", id = 503)
void unsupportedMappedSuperclassWithEntityInheritance(String entityName);
}

View File

@ -13,13 +13,20 @@ import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.MappedSuperclass;
import org.hibernate.AnnotationException;
import org.hibernate.cfg.AnnotationBinder;
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.junit.Rule;
import org.junit.Test;
import org.jboss.logging.Logger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
@ -29,6 +36,9 @@ import static org.junit.Assert.assertTrue;
@TestForIssue(jiraKey = "HHH-12653")
public class MappedSuperclassInheritanceTest extends BaseEntityManagerFunctionalTestCase {
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule( Logger.getMessageLogger( CoreMessageLogger.class, AnnotationBinder.class.getName() ) );
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
@ -40,14 +50,14 @@ public class MappedSuperclassInheritanceTest extends BaseEntityManagerFunctional
@Override
public void buildEntityManagerFactory() {
try {
super.buildEntityManagerFactory();
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000503:" );
triggerable.reset();
assertFalse( triggerable.wasTriggered() );
throw new IllegalStateException( "Should have thrown AnnotationException" );
}
catch (AnnotationException expected) {
assertTrue(expected.getMessage().startsWith( "An entity cannot be annotated with both @Inheritance and @MappedSuperclass" ));
}
super.buildEntityManagerFactory();
assertTrue( triggerable.wasTriggered() );
assertTrue( triggerable.triggerMessage().contains( "An entity cannot be annotated with both @Inheritance and @MappedSuperclass" ) );
}
@Test