You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by ja...@apache.org on 2026/04/02 15:40:32 UTC
(grails-core) branch fix/groovy-proxy-isinitialized created (now e0e272c49a)
This is an automated email from the ASF dual-hosted git repository.
jamesfredley pushed a change to branch fix/groovy-proxy-isinitialized
in repository https://gitbox.apache.org/repos/asf/grails-core.git
at e0e272c49a fix: add Groovy proxy support to HibernateProxyHandler.isInitialized()
This branch includes the following new commits:
new e0e272c49a fix: add Groovy proxy support to HibernateProxyHandler.isInitialized()
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(grails-core) 01/01: fix: add Groovy proxy support to HibernateProxyHandler.isInitialized()
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jamesfredley pushed a commit to branch fix/groovy-proxy-isinitialized
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit e0e272c49aade66068d05681d6e4a22607e15af4
Author: James Fredley <ja...@users.noreply.github.com>
AuthorDate: Thu Apr 2 11:40:16 2026 -0400
fix: add Groovy proxy support to HibernateProxyHandler.isInitialized()
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 <op...@opencode.ai>
---
.../hibernate/proxy/GroovyProxyInterceptorLogic.java | 12 ++++++++++++
.../orm/hibernate/proxy/HibernateProxyHandler.java | 5 +++++
.../hibernate/proxy/HibernateProxyHandler7Spec.groovy | 17 +++++++++++++++++
3 files changed, 34 insertions(+)
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/proxy/GroovyProxyInterceptorLogic.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/proxy/GroovyProxyInterceptorLogic.java
index 3888fedf07..af593e0c85 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/proxy/GroovyProxyInterceptorLogic.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/proxy/GroovyProxyInterceptorLogic.java
@@ -109,5 +109,17 @@ public class GroovyProxyInterceptorLogic {
return null;
}
+ /**
+ * Check if a Groovy proxy is initialized.
+ * @return {@code true} if initialized, {@code false} if not initialized, or {@code null} if the object is not a Groovy proxy
+ */
+ public static Boolean isInitialized(Object o) {
+ ProxyInstanceMetaClass proxyMc = getProxyInstanceMetaClass(o);
+ if (proxyMc != null) {
+ return proxyMc.isProxyInitiated();
+ }
+ return null;
+ }
+
public record InterceptorState(String entityName, Class<?> persistentClass, Object identifier) {}
}
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler.java
index 15786b1c6c..5acb41dbdf 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler.java
@@ -58,6 +58,11 @@ public class HibernateProxyHandler implements ProxyHandler, ProxyFactory {
return li.wasInitialized();
}
+ Boolean groovyProxyInit = GroovyProxyInterceptorLogic.isInitialized(o);
+ if (groovyProxyInit != null) {
+ return groovyProxyInit;
+ }
+
return Hibernate.isInitialized(o);
}
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler7Spec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler7Spec.groovy
index 5d3b1eaf5b..7915f1bdb6 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler7Spec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler7Spec.groovy
@@ -145,6 +145,23 @@ class HibernateProxyHandler7Spec extends HibernateGormDatastoreSpec {
proxyHandler.isInitialized(location)
}
+ void "test isInitialized for a Groovy proxy before initialization"() {
+ given:
+ def originalFactory = manager.session.mappingContext.proxyFactory
+ manager.session.mappingContext.proxyFactory = new GroovyProxyFactory()
+ Location location = new Location(name: "Test Location").save(flush: true)
+ manager.session.clear()
+ manager.hibernateSession.clear()
+
+ Location proxyLocation = Location.proxy(location.id)
+
+ expect:
+ !proxyHandler.isInitialized(proxyLocation)
+
+ cleanup:
+ manager.session.mappingContext.proxyFactory = originalFactory
+ }
+
void "test unwrap for a Groovy proxy"() {
given:
def originalFactory = manager.session.mappingContext.proxyFactory