diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/ByteBuddyState.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/ByteBuddyState.java index fa32e018b7..593773e6fd 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/ByteBuddyState.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/ByteBuddyState.java @@ -189,6 +189,10 @@ public Unloaded make(Function> makeProxyFun return make( makeProxyFunction.apply( byteBuddy ) ); } + public Unloaded make(TypePool typePool, Function> makeProxyFunction) { + return make( typePool, makeProxyFunction.apply( byteBuddy ) ); + } + private Unloaded make(DynamicType.Builder builder) { return make( null, builder ); } diff --git a/hibernate-core/src/main/java/org/hibernate/proxy/pojo/bytebuddy/ByteBuddyProxyHelper.java b/hibernate-core/src/main/java/org/hibernate/proxy/pojo/bytebuddy/ByteBuddyProxyHelper.java index aef29ba71e..44186a09aa 100644 --- a/hibernate-core/src/main/java/org/hibernate/proxy/pojo/bytebuddy/ByteBuddyProxyHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/proxy/pojo/bytebuddy/ByteBuddyProxyHelper.java @@ -10,6 +10,7 @@ import java.io.Serializable; import java.lang.reflect.Method; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Locale; @@ -27,9 +28,13 @@ import net.bytebuddy.NamingStrategy; import net.bytebuddy.TypeCache; import net.bytebuddy.description.modifier.Visibility; +import net.bytebuddy.description.type.TypeDefinition; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.description.type.TypeList; import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy; import net.bytebuddy.implementation.SuperMethodCall; +import net.bytebuddy.pool.TypePool; public class ByteBuddyProxyHelper implements Serializable { @@ -52,22 +57,34 @@ public Class buildProxy( } Collections.addAll( key, interfaces ); - return byteBuddyState.loadProxy( persistentClass, new TypeCache.SimpleKey( key ), proxyBuilder( persistentClass, interfaces ) ); + return byteBuddyState.loadProxy( persistentClass, new TypeCache.SimpleKey( key ), + proxyBuilder( TypeDescription.ForLoadedType.of( persistentClass ), new TypeList.Generic.ForLoadedTypes( interfaces ) ) ); + } + + /** + * @deprecated Use {@link #buildUnloadedProxy(TypePool, TypeDefinition, Collection)} instead. + */ + @Deprecated + public DynamicType.Unloaded buildUnloadedProxy(final Class persistentClass, final Class[] interfaces) { + return byteBuddyState.make( proxyBuilder( TypeDescription.ForLoadedType.of( persistentClass ), + new TypeList.Generic.ForLoadedTypes( interfaces ) ) ); } /** * Do not remove: used by Quarkus */ - public DynamicType.Unloaded buildUnloadedProxy(final Class persistentClass, final Class[] interfaces) { - return byteBuddyState.make( proxyBuilder( persistentClass, interfaces ) ); + public DynamicType.Unloaded buildUnloadedProxy(TypePool typePool, TypeDefinition persistentClass, + Collection interfaces) { + return byteBuddyState.make( typePool, proxyBuilder( persistentClass, interfaces ) ); } - private Function> proxyBuilder(Class persistentClass, Class[] interfaces) { + private Function> proxyBuilder(TypeDefinition persistentClass, + Collection interfaces) { ByteBuddyState.ProxyDefinitionHelpers helpers = byteBuddyState.getProxyDefinitionHelpers(); return byteBuddy -> byteBuddy .ignore( helpers.getGroovyGetMetaClassFilter() ) - .with( new NamingStrategy.SuffixingRandom( PROXY_NAMING_SUFFIX, new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( persistentClass.getName() ) ) ) - .subclass( interfaces.length == 1 ? persistentClass : Object.class, ConstructorStrategy.Default.IMITATE_SUPER_CLASS_OPENING ) + .with( new NamingStrategy.SuffixingRandom( PROXY_NAMING_SUFFIX, new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( persistentClass.getTypeName() ) ) ) + .subclass( interfaces.size() == 1 ? persistentClass : TypeDescription.OBJECT, ConstructorStrategy.Default.IMITATE_SUPER_CLASS_OPENING ) .implement( interfaces ) .method( helpers.getVirtualNotFinalizerFilter() ) .intercept( helpers.getDelegateToInterceptorDispatcherMethodDelegation() )