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:
parent
14f5473fef
commit
b1ffde0e94
|
@ -561,10 +561,7 @@ public final class AnnotationBinder {
|
||||||
if(superEntity != null && (
|
if(superEntity != null && (
|
||||||
clazzToProcess.getAnnotation( AttributeOverride.class ) != null ||
|
clazzToProcess.getAnnotation( AttributeOverride.class ) != null ||
|
||||||
clazzToProcess.getAnnotation( AttributeOverrides.class ) != null ) ) {
|
clazzToProcess.getAnnotation( AttributeOverrides.class ) != null ) ) {
|
||||||
throw new AnnotationException(
|
LOG.unsupportedAttributeOverrideWithEntityInheritance( clazzToProcess.getName() );
|
||||||
"An entity annotated with @Inheritance cannot use @AttributeOverride or @AttributeOverrides: " +
|
|
||||||
clazzToProcess.getName()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistentClass persistentClass = makePersistentClass( inheritanceState, superEntity, context );
|
PersistentClass persistentClass = makePersistentClass( inheritanceState, superEntity, context );
|
||||||
|
@ -3004,7 +3001,7 @@ public final class AnnotationBinder {
|
||||||
column.setUpdatable( false );
|
column.setUpdatable( false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final JoinColumn joinColumn = property.getAnnotation( JoinColumn.class );
|
final JoinColumn joinColumn = property.getAnnotation( JoinColumn.class );
|
||||||
final JoinColumns joinColumns = property.getAnnotation( JoinColumns.class );
|
final JoinColumns joinColumns = property.getAnnotation( JoinColumns.class );
|
||||||
|
|
||||||
|
|
|
@ -1830,4 +1830,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
||||||
@LogMessage(level = DEBUG)
|
@LogMessage(level = DEBUG)
|
||||||
@Message(value = "Detaching an uninitialized collection with queued operations from a session due to rollback: %s", id = 498)
|
@Message(value = "Detaching an uninitialized collection with queued operations from a session due to rollback: %s", id = 498)
|
||||||
void queuedOperationWhenDetachFromSessionOnRollback(String collectionInfoString);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,36 +6,39 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.override.inheritance;
|
package org.hibernate.test.annotations.override.inheritance;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import javax.persistence.AttributeOverride;
|
import javax.persistence.AttributeOverride;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Inheritance;
|
import javax.persistence.Inheritance;
|
||||||
import javax.persistence.InheritanceType;
|
import javax.persistence.InheritanceType;
|
||||||
import javax.persistence.MappedSuperclass;
|
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.persistence.UniqueConstraint;
|
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.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
import org.hibernate.testing.FailureExpected;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
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 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
|
* @author Vlad Mihalcea
|
||||||
*/
|
*/
|
||||||
@TestForIssue( jiraKey = "HHH-12609, HHH-12654" )
|
@TestForIssue( jiraKey = "HHH-12609, HHH-12654, HHH-13172" )
|
||||||
public class EntityInheritanceAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase {
|
public class EntityInheritanceAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
|
||||||
|
Logger.getMessageLogger( CoreMessageLogger.class, AnnotationBinder.class.getName() ) );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class<?>[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
CategoryEntity.class,
|
CategoryEntity.class,
|
||||||
TaxonEntity.class,
|
TaxonEntity.class,
|
||||||
|
@ -45,13 +48,11 @@ public class EntityInheritanceAttributeOverrideTest extends BaseEntityManagerFun
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildEntityManagerFactory() {
|
public void buildEntityManagerFactory() {
|
||||||
try {
|
Triggerable warningLogged = logInspection.watchForLogMessages( "HHH000499:" );
|
||||||
super.buildEntityManagerFactory();
|
|
||||||
fail("Should throw AnnotationException");
|
super.buildEntityManagerFactory();
|
||||||
}
|
|
||||||
catch (AnnotationException e) {
|
assertTrue("A warning should have been logged for this unsupported configuration", warningLogged.wasTriggered());
|
||||||
assertTrue( e.getMessage().startsWith( "An entity annotated with @Inheritance cannot use @AttributeOverride or @AttributeOverrides" ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue