HHH-13172 Log a warning instead of throwing an exception when

@AttributeOverride is used in conjunction with entity inheritance

(cherry picked from commit 2dd008adb7)
This commit is contained in:
Guillaume Smet 2018-12-25 14:06:43 +01:00 committed by Gail Badner
parent 14f5473fef
commit b1ffde0e94
3 changed files with 23 additions and 23 deletions

View File

@ -561,10 +561,7 @@ public final class AnnotationBinder {
if(superEntity != null && (
clazzToProcess.getAnnotation( AttributeOverride.class ) != null ||
clazzToProcess.getAnnotation( AttributeOverrides.class ) != null ) ) {
throw new AnnotationException(
"An entity annotated with @Inheritance cannot use @AttributeOverride or @AttributeOverrides: " +
clazzToProcess.getName()
);
LOG.unsupportedAttributeOverrideWithEntityInheritance( clazzToProcess.getName() );
}
PersistentClass persistentClass = makePersistentClass( inheritanceState, superEntity, context );
@ -3004,7 +3001,7 @@ public final class AnnotationBinder {
column.setUpdatable( false );
}
}
final JoinColumn joinColumn = property.getAnnotation( JoinColumn.class );
final JoinColumns joinColumns = property.getAnnotation( JoinColumns.class );

View File

@ -1830,4 +1830,6 @@ public interface CoreMessageLogger extends BasicLogger {
@LogMessage(level = DEBUG)
@Message(value = "Detaching an uninitialized collection with queued operations from a session due to rollback: %s", id = 498)
void queuedOperationWhenDetachFromSessionOnRollback(String collectionInfoString);
@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);
}

View File

@ -6,36 +6,39 @@
*/
package org.hibernate.test.annotations.override.inheritance;
import static org.junit.Assert.assertTrue;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.MappedSuperclass;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.hibernate.AnnotationException;
import org.hibernate.cfg.AnnotationBinder;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.logger.LoggerInspectionRule;
import org.hibernate.testing.logger.Triggerable;
import org.jboss.logging.Logger;
import org.junit.Rule;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author Vlad Mihalcea
*/
@TestForIssue( jiraKey = "HHH-12609, HHH-12654" )
@TestForIssue( jiraKey = "HHH-12609, HHH-12654, HHH-13172" )
public class EntityInheritanceAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase {
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
Logger.getMessageLogger( CoreMessageLogger.class, AnnotationBinder.class.getName() ) );
@Override
public Class[] getAnnotatedClasses() {
public Class<?>[] getAnnotatedClasses() {
return new Class[]{
CategoryEntity.class,
TaxonEntity.class,
@ -45,13 +48,11 @@ public class EntityInheritanceAttributeOverrideTest extends BaseEntityManagerFun
@Override
public void buildEntityManagerFactory() {
try {
super.buildEntityManagerFactory();
fail("Should throw AnnotationException");
}
catch (AnnotationException e) {
assertTrue( e.getMessage().startsWith( "An entity annotated with @Inheritance cannot use @AttributeOverride or @AttributeOverrides" ) );
}
Triggerable warningLogged = logInspection.watchForLogMessages( "HHH000499:" );
super.buildEntityManagerFactory();
assertTrue("A warning should have been logged for this unsupported configuration", warningLogged.wasTriggered());
}
@Test