Skip to content

Commit

Permalink
HHH-16572 add super class checking
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Marlow <[email protected]>
  • Loading branch information
scottmarlow committed Oct 23, 2024
1 parent d093c50 commit 87e12da
Showing 1 changed file with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Optional;
import java.util.function.Supplier;

import net.bytebuddy.description.method.MethodList;
import org.hibernate.Version;
import org.hibernate.bytecode.enhance.VersionMismatchException;
import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker;
Expand Down Expand Up @@ -390,18 +389,37 @@ else if ( enhancementContext.doExtendedEnhancement( managedCtClass ) ) {
// See HHH-16572
// return true if enhancement is unsupported
private boolean unsupportedEnhancement(TypeDescription managedCtClass) {
MethodList<MethodDescription.InDefinedShape> list = managedCtClass.getDeclaredMethods();
for ( MethodDescription.InDefinedShape shape: list) {
AnnotationList annotationList = shape.getDeclaredAnnotations();

if ( annotationList.isAnnotationPresent(Id.class)) {
log.debugf( "Skipping enhancement of [%s]: due to use of [%s] annotation", managedCtClass.getName(), Id.class.getName() );
// Check for use of ID/AccessType(PROPERTY) on methods
for ( MethodDescription.InDefinedShape shape: managedCtClass.getDeclaredMethods()) {
AnnotationDescription.Loadable<Access> access = shape.getDeclaredAnnotations().ofType(Access.class);
AnnotationDescription.Loadable<Id> id = shape.getDeclaredAnnotations().ofType(Id.class);
if ( access != null && access.load().value() == AccessType.PROPERTY ) {
log.debugf("Skipping enhancement of [%s]: due to use of [%s] annotation used for property access using JavaBeans-style property accessors", managedCtClass.getName(), Access.class.getName());
return true;
} else if ( annotationList.isAnnotationPresent(Access.class)) {
log.debugf( "Skipping enhancement of [%s]: due to use of [%s] annotation", managedCtClass.getName(), Access.class.getName() );
}
else if ( id != null) {
log.debugf( "Skipping enhancement of [%s]: due to use of [%s] annotation used for property access using JavaBeans-style property accessors", managedCtClass.getName(), Id.class.getName() );
return true;
}
}

TypeDescription.Generic superclass = managedCtClass.getSuperClass();
while ( superclass != null) {
// Check for use of ID/AccessType(PROPERTY) on methods
for (MethodDescription.InGenericShape shape : superclass.getDeclaredMethods()) {
AnnotationDescription.Loadable<Access> access = shape.getDeclaredAnnotations().ofType(Access.class);
AnnotationDescription.Loadable<Id> id = shape.getDeclaredAnnotations().ofType(Id.class);
if (access != null && access.load().value() == AccessType.PROPERTY) {
log.debugf("Skipping enhancement of [%s]: due to superclass [%s] use of [%s] annotation used for property access using JavaBeans-style property accessors", managedCtClass.getName(), superclass.getActualName(), Access.class.getName());
return true;
} else if (id != null) {
log.debugf("Skipping enhancement of [%s]: due to superclass [%s] use of [%s] annotation used for property access using JavaBeans-style property accessors", managedCtClass.getName(), superclass.getActualName(), Id.class.getName());
return true;
}
}
superclass = superclass.getSuperClass();
}

return false;
}

Expand Down

0 comments on commit 87e12da

Please sign in to comment.