HHH-11284 - HHH-11404 - Fix enhancement in cases where there is some sort of inheritance
This commit is contained in:
parent
ffe62ac68b
commit
8fc0bf5202
|
@ -274,6 +274,8 @@ public class EnhancerImpl implements Enhancer {
|
|||
}
|
||||
else if ( enhancementContext.isMappedSuperclassClass( managedCtClass ) ) {
|
||||
log.infof( "Enhancing [%s] as MappedSuperclass", managedCtClass.getName() );
|
||||
|
||||
builder = builder.implement( ManagedMappedSuperclass.class );
|
||||
return transformer.applyTo( builder, true );
|
||||
}
|
||||
else if ( enhancementContext.doExtendedEnhancement( managedCtClass ) ) {
|
||||
|
@ -286,14 +288,14 @@ public class EnhancerImpl implements Enhancer {
|
|||
}
|
||||
}
|
||||
|
||||
// See HHH-10977 HHH-11284 HHH-11404 --- check for declaration of Managed interface on the class, not inherited
|
||||
private boolean alreadyEnhanced(TypeDescription managedCtClass) {
|
||||
if ( !managedCtClass.isAssignableTo( Managed.class ) ) {
|
||||
return false;
|
||||
for ( TypeDescription.Generic declaredInterface : managedCtClass.getInterfaces() ) {
|
||||
if ( declaredInterface.asErasure().isAssignableTo( Managed.class ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// 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 ) && managedCtClass.isAssignableTo( ManagedEntity.class )
|
||||
|| enhancementContext.isCompositeClass( managedCtClass ) && managedCtClass.isAssignableTo( ManagedComposite.class )
|
||||
|| enhancementContext.isMappedSuperclassClass( managedCtClass ) && managedCtClass.isAssignableTo( ManagedMappedSuperclass.class );
|
||||
return false;
|
||||
}
|
||||
|
||||
private DynamicType.Builder<?> addInterceptorHandling(DynamicType.Builder<?> builder, TypeDescription managedCtClass) {
|
||||
|
|
|
@ -18,15 +18,13 @@ import javassist.ClassPool;
|
|||
import javassist.CtClass;
|
||||
import javassist.LoaderClassPath;
|
||||
|
||||
import javassist.NotFoundException;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
|
||||
import org.hibernate.bytecode.enhance.spi.EnhancementException;
|
||||
import org.hibernate.bytecode.enhance.spi.Enhancer;
|
||||
import org.hibernate.bytecode.enhance.spi.EnhancerConstants;
|
||||
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;
|
||||
|
@ -159,20 +157,19 @@ public class EnhancerImpl implements 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) {
|
||||
|
|
Loading…
Reference in New Issue