HHH-11284 - HHH-11404 - Fix enhancement in cases where there is some sort of inheritance

This commit is contained in:
barreiro 2017-01-24 10:25:04 +00:00
parent deefb11e9d
commit 919557f250
No known key found for this signature in database
GPG Key ID: B56FFB7502C31F42
1 changed files with 11 additions and 8 deletions

View File

@ -16,6 +16,7 @@ import javassist.ClassPool;
import javassist.CtClass;
import javassist.LoaderClassPath;
import javassist.NotFoundException;
import org.hibernate.HibernateException;
import org.hibernate.bytecode.enhance.internal.CompositeEnhancer;
import org.hibernate.bytecode.enhance.internal.EntityEnhancer;
@ -24,9 +25,6 @@ import org.hibernate.bytecode.enhance.internal.MappedSuperclassEnhancer;
import org.hibernate.bytecode.enhance.internal.PersistentAttributesEnhancer;
import org.hibernate.bytecode.enhance.internal.PersistentAttributesHelper;
import org.hibernate.engine.spi.Managed;
import org.hibernate.engine.spi.ManagedComposite;
import org.hibernate.engine.spi.ManagedEntity;
import org.hibernate.engine.spi.ManagedMappedSuperclass;
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
import org.hibernate.internal.CoreLogging;
@ -146,14 +144,19 @@ public class Enhancer {
}
}
// See HHH-10977 HHH-11284 HHH-11404 --- check for declaration of Managed interface on the class, not inherited
private boolean alreadyEnhanced(CtClass managedCtClass) {
if ( !PersistentAttributesHelper.isAssignable( managedCtClass, Managed.class.getName() ) ) {
try {
for ( CtClass declaredInterface : managedCtClass.getInterfaces() ) {
if ( PersistentAttributesHelper.isAssignable( declaredInterface, Managed.class.getName() ) ) {
return true;
}
}
return false;
}
// HHH-10977 - When a mapped superclass gets enhanced before a subclassing entity, the entity does not get enhanced, but it implements the Managed interface
return enhancementContext.isEntityClass( managedCtClass ) && PersistentAttributesHelper.isAssignable( managedCtClass, ManagedEntity.class.getName() )
|| enhancementContext.isCompositeClass( managedCtClass ) && PersistentAttributesHelper.isAssignable( managedCtClass, ManagedComposite.class.getName() )
|| enhancementContext.isMappedSuperclassClass( managedCtClass ) && PersistentAttributesHelper.isAssignable( managedCtClass, ManagedMappedSuperclass.class.getName() );
catch ( NotFoundException e ) {
throw new HibernateException( "Unable to transform class: " + e.getMessage(), e );
}
}
private byte[] getByteCode(CtClass managedCtClass) {