Skip to content

Conversation

jbescos
Copy link

@jbescos jbescos commented Sep 18, 2025

https://hibernate.atlassian.net/browse/HHH-19798

There is an stackoverflow question related to this.

I am creating the PR to version 6.6 because we had the issue there. It is likely it will need ot be backported to branch 7 and master.

Running hibernate 6.6.23.Final with Graal-VM throws the next errors:

Error: Classes that should be initialized at run time got initialized during image building:
 net.bytebuddy.description.type.TypeDescription$AbstractBase was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$AbstractBase.<clinit>(TypeDescription.java)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)

net.bytebuddy.utility.GraalImageCode was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.GraalImageCode.<clinit>(GraalImageCode.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.invoker(JavaDispatcher.java:1321)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)

net.bytebuddy.utility.dispatcher.JavaDispatcher was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)

net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.<clinit>(JavaDispatcher.java:1199)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)

net.bytebuddy.description.type.TypeDefinition$Sort was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDefinition$Sort.<clinit>(TypeDefinition.java)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:449)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:420)
	at java.util.AbstractList$Itr.next(AbstractList.java:373)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:346)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:365)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType$ForLoadedType was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType$ForLoadedType.<clinit>(TypeDescription.java:3929)
	at net.bytebuddy.description.type.TypeDefinition$Sort.describe(TypeDefinition.java:270)
	at net.bytebuddy.description.type.TypeDefinition$Sort.describe(TypeDefinition.java:244)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:449)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:420)
	at java.util.AbstractList$Itr.next(AbstractList.java:373)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:346)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:365)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDescription$ForLoadedType was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)

net.bytebuddy.ClassFileVersion was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.ClassFileVersion.<clinit>(ClassFileVersion.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.invoker(JavaDispatcher.java:1315)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)


com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 net.bytebuddy.description.type.TypeDescription$AbstractBase was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$AbstractBase.<clinit>(TypeDescription.java)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)

net.bytebuddy.utility.GraalImageCode was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.GraalImageCode.<clinit>(GraalImageCode.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.invoker(JavaDispatcher.java:1321)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)

net.bytebuddy.utility.dispatcher.JavaDispatcher was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)

net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.<clinit>(JavaDispatcher.java:1199)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)

net.bytebuddy.description.type.TypeDefinition$Sort was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDefinition$Sort.<clinit>(TypeDefinition.java)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:449)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:420)
	at java.util.AbstractList$Itr.next(AbstractList.java:373)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:346)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:365)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType$ForLoadedType was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType$ForLoadedType.<clinit>(TypeDescription.java:3929)
	at net.bytebuddy.description.type.TypeDefinition$Sort.describe(TypeDefinition.java:270)
	at net.bytebuddy.description.type.TypeDefinition$Sort.describe(TypeDefinition.java:244)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:449)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:420)
	at java.util.AbstractList$Itr.next(AbstractList.java:373)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:346)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:365)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDescription$ForLoadedType was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)

net.bytebuddy.ClassFileVersion was unintentionally initialized at build time. org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper caused initialization of this class with the following trace: 
	at net.bytebuddy.ClassFileVersion.<clinit>(ClassFileVersion.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.invoker(JavaDispatcher.java:1315)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.<clinit>(ByteBuddyProxyHelper.java:44)


	at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.UserError.abort(UserError.java:75)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.classinitialization.ProvenSafeClassInitializationSupport.checkDelayedInitialization(ProvenSafeClassInitializationSupport.java:277)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:219)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$10(NativeImageGenerator.java:787)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:90)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$11(NativeImageGenerator.java:787)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.AbstractAnalysisEngine.runAnalysis(AbstractAnalysisEngine.java:181)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:784)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:593)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:551)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:539)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:721)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.start(NativeImageGeneratorRunner.java:143)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:98)



Error: Classes that should be initialized at run time got initialized during image building:
 net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.<clinit>(JavaDispatcher.java:1199)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.ClassFileVersion was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.ClassFileVersion.<clinit>(ClassFileVersion.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.invoker(JavaDispatcher.java:1315)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDefinition$Sort was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDefinition$Sort.<clinit>(TypeDefinition.java)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:449)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:420)
	at java.util.AbstractList$Itr.next(AbstractList.java:373)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:346)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:365)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDescription$ForLoadedType was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.utility.dispatcher.JavaDispatcher was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType$ForLoadedType was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType$ForLoadedType.<clinit>(TypeDescription.java:3929)
	at net.bytebuddy.description.type.TypeDefinition$Sort.describe(TypeDefinition.java:270)
	at net.bytebuddy.description.type.TypeDefinition$Sort.describe(TypeDefinition.java:244)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:449)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:420)
	at java.util.AbstractList$Itr.next(AbstractList.java:373)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:346)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:365)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.utility.GraalImageCode was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.GraalImageCode.<clinit>(GraalImageCode.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.invoker(JavaDispatcher.java:1321)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDescription$AbstractBase was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$AbstractBase.<clinit>(TypeDescription.java)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)


com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.<clinit>(JavaDispatcher.java:1199)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.ClassFileVersion was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.ClassFileVersion.<clinit>(ClassFileVersion.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.invoker(JavaDispatcher.java:1315)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDefinition$Sort was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDefinition$Sort.<clinit>(TypeDefinition.java)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:449)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:420)
	at java.util.AbstractList$Itr.next(AbstractList.java:373)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:346)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:365)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDescription$ForLoadedType was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.utility.dispatcher.JavaDispatcher was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType$ForLoadedType was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType$ForLoadedType.<clinit>(TypeDescription.java:3929)
	at net.bytebuddy.description.type.TypeDefinition$Sort.describe(TypeDefinition.java:270)
	at net.bytebuddy.description.type.TypeDefinition$Sort.describe(TypeDefinition.java:244)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:449)
	at net.bytebuddy.description.type.TypeList$Generic$ForLoadedTypes.get(TypeList.java:420)
	at java.util.AbstractList$Itr.next(AbstractList.java:373)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:346)
	at net.bytebuddy.matcher.ElementMatchers.anyOf(ElementMatchers.java:365)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.utility.GraalImageCode was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.utility.GraalImageCode.<clinit>(GraalImageCode.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.invoker(JavaDispatcher.java:1321)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:460)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:453)
	at java.security.AccessController.executePrivileged(AccessController.java:778)
	at java.security.AccessController.doPrivileged(AccessController.java:319)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:88)
	at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8725)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)

net.bytebuddy.description.type.TypeDescription$AbstractBase was unintentionally initialized at build time. org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext caused initialization of this class with the following trace: 
	at net.bytebuddy.description.type.TypeDescription$AbstractBase.<clinit>(TypeDescription.java)
	at net.bytebuddy.matcher.ElementMatchers.isGetter(ElementMatchers.java:1764)
	at org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext.<clinit>(ByteBuddyEnhancementContext.java:33)


	at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.UserError.abort(UserError.java:75)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.classinitialization.ProvenSafeClassInitializationSupport.checkDelayedInitialization(ProvenSafeClassInitializationSupport.java:277)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:219)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$10(NativeImageGenerator.java:787)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:90)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$11(NativeImageGenerator.java:787)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.AbstractAnalysisEngine.runAnalysis(AbstractAnalysisEngine.java:181)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:784)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:593)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:551)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:539)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:721)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.start(NativeImageGeneratorRunner.java:143)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:98)

It seems the issue was added here:
commit e6c106f52796a0065f0181462adc83ec4b52be3c Author: Philippe Marschall <philippe.marschall@gmail.com> 2023-12-28 13:47:24 Committer: Christian Beikov <christian.beikov@gmail.com> 2024-03-14 16:16:52 Parent: 8ebf3c8507bce339bc63cdd76e6869c2fbd975a7 (HHH-15809 Secondary super-type cache pollution mitigations for HibernateBasicProxy) Child: 73c490c37edde44e778eaef5ef709f6821a70094 (HHH-14694 Use stable proxy names to avoid managing proxy state) Child: f805bcec639f99642a7f0d63ee8fb35c989369e0 (cleanups, especially to useless uses of JBoss logging) Branches: 6.6, issueNI, main, origin, hibernate/6.5, hibernate/6.6, hibernate/7.0, hibernate/7.1, hibernate/dependabot/gradle/build-dependencies-7c72a25b7f, hibernate/dependabot/gradle/io.smallrye-jandex-3.5.0, hibernate/dependabot/gradle/jakarta-366b247967, hibernate/main, origin/HEAD, origin/main HHH-17596 Use new Byte Buddy API Update code to replace deprecated Byte Buddy code with replacement.

Fix is about making the static fields Lazy. I noticed the class LazyValue was not thread safe. I am fixing that too.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Sep 18, 2025

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@jbescos
Copy link
Author

jbescos commented Sep 18, 2025

Thanks for your pull request!

This pull request does not follow the contribution rules. Could you have a look?

❌ All commit messages should start with a JIRA issue key matching pattern HHH-\d+     ↳ Offending commits: [aa03b1b]

› This message was automatically generated.

I don't have rights to create Jira issues, how can I do that?.

One college helped me and created the issue https://hibernate.atlassian.net/browse/HHH-19798

@jbescos jbescos changed the title Graal-VM initialization issues HHH-19798 - Graal-VM initialization issues Sep 22, 2025
@jbescos jbescos force-pushed the issueNI branch 2 times, most recently from 0735309 to dcfd1a8 Compare September 22, 2025 10:17
@Sanne
Copy link
Member

Sanne commented Sep 23, 2025

Hi hello!

If GraalVM is failing on these constants, it means that it determined that these constants are reachable at runtime - otherwise this would be removed by its clever dead-code elimination process, and it wouldn't fail.
Making the constant lazy might get you past the build issue, but it would hide the problem and potentially introduce a critical failure at runtime - this might not be visible in a simple test but it implies you might be hiding a critical bug.

It would be better to determine why in your case the compiler has determined that this constant is necessary; at the very least you'd need this to determine how it might fail if you decided to apply such a patch.

In general we made Hibernate ORM work very well in native-image but the general pattern is to have any code which needs bytebuddy to be executed at build time, as it's not currently possible to generate bytecode during the runtime of native image.

So

  1. use build time enhancement
  2. avoid situations needing an enhanced proxy - or pre-generate them in some way ( pregenerating is tricky and would depend on your stack - for example I don't know how to do this on Spring, while on Quarkus it's taken care of automatically)

Perhaps if you could tell me more about what stack you're running I might be able to give some better suggestions.

@jbescos
Copy link
Author

jbescos commented Sep 23, 2025

Hi hello!

If GraalVM is failing on these constants, it means that it determined that these constants are reachable at runtime - otherwise this would be removed by its clever dead-code elimination process, and it wouldn't fail. Making the constant lazy might get you past the build issue, but it would hide the problem and potentially introduce a critical failure at runtime - this might not be visible in a simple test but it implies you might be hiding a critical bug.

It would be better to determine why in your case the compiler has determined that this constant is necessary; at the very least you'd need this to determine how it might fail if you decided to apply such a patch.

In general we made Hibernate ORM work very well in native-image but the general pattern is to have any code which needs bytebuddy to be executed at build time, as it's not currently possible to generate bytecode during the runtime of native image.

So

  1. use build time enhancement
  2. avoid situations needing an enhanced proxy - or pre-generate them in some way ( pregenerating is tricky and would depend on your stack - for example I don't know how to do this on Spring, while on Quarkus it's taken care of automatically)

Perhaps if you could tell me more about what stack you're running I might be able to give some better suggestions.

Hello,

Thanks for responding. This is happening within the stack of Helidon, I wrote before the steps to reproduce it. In that example, we already use build time enhancement with the next, but still bytebuddy gets loaded with the stacktraces I show before:

            <plugin>
                <groupId>org.hibernate.orm.tooling</groupId>
                <artifactId>hibernate-enhance-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>Statically enhance JPA entities for Hibernate</id>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                        <configuration>
                            <failOnError>true</failOnError>
                            <enableLazyInitialization>true</enableLazyInitialization>
                            <enableDirtyTracking>true</enableDirtyTracking>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

The problem is that the next triggers reflection when classes ByteBuddyEnhancementContext and ByteBuddyProxyHelper are loaded. Note this has nothing to do with static enhancement nor proxies:

private static final TypeDescription OBJECT = TypeDescription.ForLoadedType.of(Object.class);
private static final ElementMatcher.Junction<MethodDescription> IS_GETTER = isGetter();

If lazy load does not work for you, I will try to find out other solution.

@jbescos
Copy link
Author

jbescos commented Sep 24, 2025

I’ve been experimenting with different solutions, but none of them worked so far because they introduced new issues. Since ByteBuddy enhancement shouldn’t be triggered when there are no proxies (as the classes are already enhanced at build time), what kind of error do you think could arise in this situation?.

Instead of using LazyValue, we could make the variables final non static. It looks these classes are coming from the service loader org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl, which is not supposed to be used with static enhancement.

Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
@jbescos
Copy link
Author

jbescos commented Sep 25, 2025

I managed to fix it in Helidon, doing some class replacements/substitutions. Although the solution I applied there is weak for future changes in Hibernate, so it would be preferable to fix it here.

For the record, this is the fix I did in Helidon.

@Sanne
Copy link
Member

Sanne commented Sep 25, 2025

The problem is that the next triggers reflection when classes ByteBuddyEnhancementContext and ByteBuddyProxyHelper are loaded.

Can you try figure out why these classes are being loaded at all? Obviously there should be no bytecode processing happening during the runtime execution in native-image.

@Sanne
Copy link
Member

Sanne commented Sep 25, 2025

I managed to fix it in Helidon, doing some class replacements/substitutions. Although the solution I applied there is weak for future changes in Hibernate, so it would be preferable to fix it here.

For the record, this is the fix I did in Helidon.

Interesting, thanks! I've added some comments on there.

@Sanne
Copy link
Member

Sanne commented Sep 25, 2025

FWIW, I think the better solution would be to implement:

In this way, you'd be able to fully exclude the Bytebuddy related code from the application being compiled to native.

It's been on my wishlist for some time, but I haven't personally found the time to do it. Perhaps you'd want to try that?

@jbescos
Copy link
Author

jbescos commented Sep 25, 2025

The problem is that the next triggers reflection when classes ByteBuddyEnhancementContext and ByteBuddyProxyHelper are loaded.

Can you try figure out why these classes are being loaded at all? Obviously there should be no bytecode processing happening during the runtime execution in native-image.

I am not expert in Graal VM, but it looks to me that it tries to resolve any static field and if that triggers reflection, it fails. Either, don't use static fields related to reflection (you can keep them as not static in factories or service loaders), or not bound hibernate-core to bytebuddy (this can be in a separate jar).

An immediate fix is to keep these problematic variables as non-static or static lazy loaded.

@Sanne
Copy link
Member

Sanne commented Sep 25, 2025

I am not expert in Graal VM, but it looks to me that it tries to resolve any static field and if that triggers reflection, it fails.

No it will only trigger initialization of constants which it has a (fairly accurate?) reason to believe they will be required at runtime. And it's usually right, that's why I'm suggesting to try figure out why this is being included at all.

Either, don't use static fields related to reflection (you can keep them as not static in factories or service loaders), or not bound hibernate-core to bytebuddy (this can be in a separate jar).

The proof is that this isn't a problem in Quarkus, they upgraded to this Hibernate version a long time ago.

@jbescos
Copy link
Author

jbescos commented Sep 25, 2025

I am not expert in Graal VM, but it looks to me that it tries to resolve any static field and if that triggers reflection, it fails.

No it will only trigger initialization of constants which it has a (fairly accurate?) reason to believe they will be required at runtime. And it's usually right, that's why I'm suggesting to try figure out why this is being included at all.

Either, don't use static fields related to reflection (you can keep them as not static in factories or service loaders), or not bound hibernate-core to bytebuddy (this can be in a separate jar).

The proof is that this isn't a problem in Quarkus, they upgraded to this Hibernate version a long time ago.

Then Graal VM should show the origin of this, but unfortunately the only stacks I found is what I already printed in my first comment. The origin in those stacks are ByteBuddyProxyHelper and ByteBuddyEnhancementContext.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants