fix: add Groovy proxy support to HibernateProxyHandler.isInitialized()#15548
fix: add Groovy proxy support to HibernateProxyHandler.isInitialized()#15548jamesfredley merged 2 commits into8.0.x-hibernate7from
Conversation
The Hibernate 7 HibernateProxyHandler.isInitialized() was missing a check for Groovy proxies (ProxyInstanceMetaClass), causing uninitialized Groovy proxies to be incorrectly reported as initialized. This is because the fallback Hibernate.isInitialized() returns true for any non-Hibernate object. Add GroovyProxyInterceptorLogic.isInitialized() helper that checks ProxyInstanceMetaClass.isProxyInitiated(), and call it from HibernateProxyHandler.isInitialized() before the Hibernate fallback. The Hibernate 5 implementation already had this check. This restores parity and adds the corresponding test. Assisted-by: OpenCode <opencode@opencode.ai>
There was a problem hiding this comment.
Pull request overview
Adds Groovy proxy awareness to HibernateProxyHandler.isInitialized() in Hibernate 7 to prevent uninitialized Groovy proxies from being incorrectly reported as initialized, restoring behavior parity with Hibernate 5.
Changes:
- Added
GroovyProxyInterceptorLogic.isInitialized(Object)tri-state helper for Groovy proxies. - Updated
HibernateProxyHandler.isInitialized()to consult Groovy proxy state before falling back toHibernate.isInitialized(). - Added a new spec verifying
isInitializedreturnsfalsefor an uninitialized Groovy proxy.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/proxy/GroovyProxyInterceptorLogic.java | Adds Groovy-proxy initialization detection helper. |
| grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler.java | Uses the Groovy-proxy helper prior to Hibernate fallback. |
| grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler7Spec.groovy | Adds regression test for uninitialized Groovy proxy initialization reporting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Rename groovyProxyInit to groovyProxyInitialized for clearer state semantics - Add ProxyInstanceMetaClass precondition assertion in Groovy proxy test Assisted-by: OpenCode <opencode@opencode.ai>
✅ All tests passed ✅🏷️ Commit: 148d718 Learn more about TestLens at testlens.app. |
jdaugherty
left a comment
There was a problem hiding this comment.
I'm confused, historically GroovyProxies were not used in hibernate. A different proxy mechanism was used. Was this a change with the hibernate 7 implementation? (see GroovyProxySpec for history)
|
You're right - Groovy proxies ( Hibernate uses its own proxy mechanism (ByteBuddy/Javassist However, H5's This PR restores that same defensive behavior in H7's handler for parity. |
Summary
HibernateProxyHandler.isInitialized()in Hibernate 7 was missing Groovy proxy support, causing uninitialized Groovy proxies to be incorrectly reported as initialized. The fallbackHibernate.isInitialized()returnstruefor any non-Hibernate object, masking the bug.GroovyProxyInterceptorLogic.isInitialized()helper that checksProxyInstanceMetaClass.isProxyInitiated(), and invoke it fromHibernateProxyHandler.isInitialized()before the Hibernate fallback.Changes
GroovyProxyInterceptorLogic.javaisInitialized(Object)static helper methodHibernateProxyHandler.javaGroovyProxyInterceptorLogic.isInitialized()beforeHibernate.isInitialized()fallbackHibernateProxyHandler7Spec.groovyTesting
All 21
HibernateProxyHandler7Spectests pass, including the new Groovy proxyisInitializedtest.