-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Make it easier to enable Hibernate bytecode enhancement #22109
Comments
Also fiddled around with that half a day. Just couldn't get it to work, neither with Gradle Plugin or on runtime. The Gradle plugin simply does not enhance the classes at all. |
In the stacktrace it is mentioned to |
This has been working well for those using GraalVM where the enhancement has to be done ahead-of-time. As such, it's our recommended approach for everyone.
Thankfully, this is no longer the case and you can now use the plugins DSL to apply the Hibernate plugin.
That is the one downside at the moment. It could be addressed by a Boot-provided settings plugin or version catalog. This would provide a more general solution to managing Gradle plugin versions for things like GraalVM's native build tools as well as Hibernate. I've opened #37836 for that. Given the focus on build-time enhancement I don't think we should do anything in this area for the runtime side of things. As such, I'm going to close this in favor of using the |
Using Spring Boot 2.3.1.
I'm setting up a Spring Boot web application using Tomcat+JPA+Hibernate. I then wanted to enable bytecode enhancement for Hibernate.
The first attempt was to just add the following properties to my
application.properties
(just mentioning a couple of them), to enable runtime bytecode enhancement:This, however, produces this at runtime:
So, the error is suggesting load time weaving support is required. I'm not an expert in this area, but I could not find any mention to the fact that bytecode enhancement in Hibernate 5 requires load time weaving to be enabled. Anyway, I remembered that Tomcat should support load time weaving without the need of any external agent, so the next step I took was to add
@EnableLoadTimeWeaving
to my Spring Boot app. The error is then:Possibly a problem related to Spring Boot Dev Tools? No, because if I remove them, I still get:
So, if I understand it well, Spring Boot classloaders are in some way shielding the (wrapped?) Tomcat class loader and do not support specifying a
ClassFileTransformer
. Or the Tomcat class loader is not used at all by Spring Boot?Searching with Google I understand that this problem may be fixed by providing a bean of type
org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver
and using the Spring Java agent.Others seems to suggest to use the AspectJ agent instead, without
@EnableLoadTimeWeaving
(https://stackoverflow.com/questions/54749106/aspectj-ltw-weaving-not-working-with-spring-boot), although it's not clear to me whether this would satisfy my use case.There's also a weaver implementation that seems to be agentless: https://github.com/subes/invesdwin-instrument
While this report seems to be encouraging, but substantially still: #739
In any case, this is quite a mess and there's no chapter in Spring Boot documentation to clarify how this should be better done.
So, by now I opted for build-time enhancement using the Hibernate Gradle Plugin, not without difficulties: it still uses the old-style way to apply plugins and you have to keep the Hibernate Gradle Plugin version manually aligned to the one used by Spring Boot because you can't use the Spring Boot BOM for that.
The text was updated successfully, but these errors were encountered: