Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibernate throws EnhancementException for embedded field in MappedSuperclass #24494

Closed
markusdlugi opened this issue Mar 23, 2022 · 3 comments · Fixed by #24912
Closed

Hibernate throws EnhancementException for embedded field in MappedSuperclass #24494

markusdlugi opened this issue Mar 23, 2022 · 3 comments · Fixed by #24912
Assignees
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Milestone

Comments

@markusdlugi
Copy link
Contributor

Describe the bug

Similar to #5756, possibly a regression?

If you have an embedded field in a @MappedSuperclass that resides in a different package then the concrete entity class, Hibernate (both Reactive and ORM) will throw an error during the application build:

[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:2.7.5.Final:build (default) on project hibernate-enhancement-exception: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] 	[error]: Build step io.quarkus.deployment.steps.ClassTransformingBuildStep#handleClassTransformation threw an exception: java.lang.IllegalStateException: java.util.concurrent.ExecutionException: org.hibernate.bytecode.enhance.spi.EnhancementException: Failed to enhance class org.acme.a.TestEntity
[ERROR] 	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:891)
[ERROR] 	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
[ERROR] 	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
[ERROR] 	at java.base/java.lang.Thread.run(Thread.java:829)
[ERROR] 	at org.jboss.threads.JBossThread.run(JBossThread.java:501)
[ERROR] Caused by: java.util.concurrent.ExecutionException: org.hibernate.bytecode.enhance.spi.EnhancementException: Failed to enhance class org.acme.a.TestEntity
[ERROR] 	at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
[ERROR] 	at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
[ERROR] 	at io.quarkus.deployment.steps.ClassTransformingBuildStep.handleClassTransformation(ClassTransformingBuildStep.java:232)
[ERROR] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR] 	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:882)
[ERROR] 	... 6 more
[ERROR] Caused by: org.hibernate.bytecode.enhance.spi.EnhancementException: Failed to enhance class org.acme.a.TestEntity
[ERROR] 	at org.hibernate.bytecode.enhance.internal.bytebuddy.EnhancerImpl.enhance(EnhancerImpl.java:138)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.HibernateEntityEnhancer$HibernateEnhancingClassVisitor.hibernateEnhancement(HibernateEntityEnhancer.java:86)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.HibernateEntityEnhancer$HibernateEnhancingClassVisitor.visitEnd(HibernateEntityEnhancer.java:79)
[ERROR] 	at org.objectweb.asm.ClassReader.accept(ClassReader.java:748)
[ERROR] 	at org.objectweb.asm.ClassReader.accept(ClassReader.java:424)
[ERROR] 	at io.quarkus.deployment.steps.ClassTransformingBuildStep.transformClass(ClassTransformingBuildStep.java:321)
[ERROR] 	at io.quarkus.deployment.steps.ClassTransformingBuildStep$2.call(ClassTransformingBuildStep.java:205)
[ERROR] 	at io.quarkus.deployment.steps.ClassTransformingBuildStep$2.call(ClassTransformingBuildStep.java:192)
[ERROR] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[ERROR] 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[ERROR] 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[ERROR] 	at java.base/java.lang.Thread.run(Thread.java:829)
[ERROR] Caused by: java.lang.IllegalStateException: Cannot access protected org.acme.b.EmbeddableType org.acme.b.AbstractEntity.embeddedField from class org.acme.a.TestEntity
[ERROR] 	at net.bytebuddy.asm.Advice$OffsetMapping$ForField$Resolved.resolve(Advice.java:2563)
[ERROR] 	at net.bytebuddy.asm.Advice$OffsetMapping$ForField.resolve(Advice.java:2309)
[ERROR] 	at net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$ForMethodEnter.doApply(Advice.java:8684)
[ERROR] 	at net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$ForMethodEnter.apply(Advice.java:8642)
[ERROR] 	at net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$AdviceMethodInliner.visitMethod(Advice.java:8332)
[ERROR] 	at net.bytebuddy.jar.asm.ClassReader.readMethod(ClassReader.java:1353)
[ERROR] 	at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:744)
[ERROR] 	at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:424)
[ERROR] 	at net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$AdviceMethodInliner.apply(Advice.java:8325)
[ERROR] 	at net.bytebuddy.asm.Advice$AdviceVisitor.onAfterExceptionTable(Advice.java:10579)
[ERROR] 	at net.bytebuddy.utility.visitor.ExceptionTableSensitiveMethodVisitor.considerEndOfExceptionTable(ExceptionTableSensitiveMethodVisitor.java:49)
[ERROR] 	at net.bytebuddy.utility.visitor.ExceptionTableSensitiveMethodVisitor.visitVarInsn(ExceptionTableSensitiveMethodVisitor.java:113)
[ERROR] 	at org.hibernate.bytecode.enhance.internal.bytebuddy.InlineDirtyCheckingHandler.apply(InlineDirtyCheckingHandler.java:100)
[ERROR] 	at net.bytebuddy.implementation.bytecode.ByteCodeAppender$Compound.apply(ByteCodeAppender.java:156)
[ERROR] 	at net.bytebuddy.asm.Advice$Appender$EmulatingMethodVisitor.resolve(Advice.java:11185)
[ERROR] 	at net.bytebuddy.asm.Advice$Appender.apply(Advice.java:11138)
[ERROR] 	at net.bytebuddy.dynamic.scaffold.TypeWriter$MethodPool$Record$ForDefinedMethod$WithBody.applyCode(TypeWriter.java:719)
[ERROR] 	at net.bytebuddy.dynamic.scaffold.TypeWriter$MethodPool$Record$ForDefinedMethod$WithBody.applyBody(TypeWriter.java:704)
[ERROR] 	at net.bytebuddy.dynamic.scaffold.TypeWriter$MethodPool$Record$ForDefinedMethod.apply(TypeWriter.java:611)
[ERROR] 	at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForInlining$WithFullProcessing$RedefinitionClassVisitor.onVisitEnd(TypeWriter.java:5219)
[ERROR] 	at net.bytebuddy.utility.visitor.MetadataAwareClassVisitor.visitEnd(MetadataAwareClassVisitor.java:325)
[ERROR] 	at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:748)
[ERROR] 	at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:424)
[ERROR] 	at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForInlining.create(TypeWriter.java:3951)
[ERROR] 	at net.bytebuddy.dynamic.scaffold.TypeWriter$Default.make(TypeWriter.java:2213)
[ERROR] 	at net.bytebuddy.dynamic.scaffold.inline.RedefinitionDynamicTypeBuilder.make(RedefinitionDynamicTypeBuilder.java:224)
[ERROR] 	at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:3654)
[ERROR] 	at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase$Delegator.make(DynamicType.java:3913)
[ERROR] 	at org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState.make(ByteBuddyState.java:200)
[ERROR] 	at org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState.rewrite(ByteBuddyState.java:149)
[ERROR] 	at org.hibernate.bytecode.enhance.internal.bytebuddy.EnhancerImpl.enhance(EnhancerImpl.java:132)
[ERROR] 	... 11 more

You can only work around the issue by making the embedded field public.

Expected behavior

Hibernate should be able to access the field and build should work.

Actual behavior

Build is broken with exception mentioned above.

How to Reproduce?

Reproducer: https://github.com/markusdlugi/hibernate-enhancement-exception

Steps to reproduce the behavior:

  1. Start Maven build in reproducer and observe error.

Output of uname -a or ver

No response

Output of java -version

OpenJDK 64-Bit Server VM Corretto-11.0.10.9.1 (build 11.0.10+9-LTS, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.7.5.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.6.3

Additional information

No response

@markusdlugi markusdlugi added the kind/bug Something isn't working label Mar 23, 2022
@quarkus-bot quarkus-bot bot added area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE labels Mar 23, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Mar 23, 2022

/cc @Sanne, @gsmet, @yrodiere

@yrodiere yrodiere self-assigned this Mar 24, 2022
@yrodiere
Copy link
Member

Thank for the report and reproducer!

I just confirmed this is a caused by a bug upstream: https://hibernate.atlassian.net/browse/HHH-15141 .

I will try to solve the bug there.

(BTW, while this is very close to #5756 , I don't think it's a regression as the situation is slightly different; more likely the fix for #5756 was incomplete)

@yrodiere
Copy link
Member

yrodiere commented Mar 24, 2022

After further investigation, I believe this is caused by a bug in bytebuddy: raphw/byte-buddy#1224

The accessibility problem reported in the error message is in fact wrong in this case, as far as I can tell.

Let's see if the bug can get fixed easily in bytebuddy; if not, I may have to find a workaround in Hibernate ORM.

@quarkus-bot quarkus-bot bot added this to the 2.9 - main milestone Apr 13, 2022
@gsmet gsmet modified the milestones: 2.9 - main, 2.8.1.Final Apr 15, 2022
@gsmet gsmet modified the milestones: 2.8.1.Final, 2.7.6.Final May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants