Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,7 @@ public static void bindClass(
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 );
Expand Down Expand Up @@ -3004,7 +3001,7 @@ private static void bindManyToOne(
column.setUpdatable( false );
}
}

final JoinColumn joinColumn = property.getAnnotation( JoinColumn.class );
final JoinColumns joinColumns = property.getAnnotation( JoinColumns.class );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1814,4 +1814,8 @@ void attemptToAssociateProxyWithTwoOpenSessions(
@LogMessage(level = WARN)
@Message(value = "Setting " + AvailableSettings.NATIVE_EXCEPTION_HANDLING_51_COMPLIANCE + "=true is not valid with JPA bootstrapping; setting will be ignored.", id = 489 )
void nativeExceptionHandling51ComplianceJpaBootstrapping();

@LogMessage(level = WARN)
@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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -45,13 +48,11 @@ public Class[] getAnnotatedClasses() {

@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
Expand Down