File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed
src/java/org/codehaus/groovy/grails/orm/hibernate Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -324,6 +324,21 @@ public static void incrementVersion(Object target) {
324324 }
325325 }
326326
327+ /**
328+ * Ensures the meta class is correct for a given class
329+ *
330+ * @param target The GroovyObject
331+ * @param persistentClass The persistent class
332+ */
333+ public static void ensureCorrectGroovyMetaClass (Object target , Class persistentClass ) {
334+ if (target instanceof GroovyObject ) {
335+ GroovyObject go = ((GroovyObject )target );
336+ if (!go .getMetaClass ().getTheClass ().equals (persistentClass )) {
337+ go .setMetaClass (GroovySystem .getMetaClassRegistry ().getMetaClass (persistentClass ));
338+ }
339+ }
340+ }
341+
327342 /**
328343 * Unwraps and initializes a HibernateProxy.
329344 * @param proxy The proxy
Original file line number Diff line number Diff line change 1414 */
1515package org .codehaus .groovy .grails .orm .hibernate .proxy ;
1616
17+ import groovy .lang .GroovyObject ;
18+ import groovy .lang .GroovySystem ;
19+
1720import java .io .Serializable ;
1821import java .lang .reflect .InvocationTargetException ;
1922import java .lang .reflect .Method ;
2629import javassist .util .proxy .ProxyObject ;
2730
2831import org .apache .commons .logging .LogFactory ;
32+ import org .codehaus .groovy .grails .orm .hibernate .cfg .GrailsHibernateUtil ;
2933import org .codehaus .groovy .grails .plugins .orm .hibernate .HibernatePluginSupport ;
3034import org .hibernate .HibernateException ;
3135import org .hibernate .engine .SessionImplementor ;
@@ -209,6 +213,7 @@ public Object invoke(
209213 }
210214 if (result == INVOKE_IMPLEMENTATION ) {
211215 Object target = getImplementation ();
216+ GrailsHibernateUtil .ensureCorrectGroovyMetaClass (target ,persistentClass );
212217 final Object returnValue ;
213218 try {
214219 if (ReflectHelper .isPublic (persistentClass , thisMethod )) {
@@ -240,7 +245,8 @@ public Object invoke(
240245 return proceed .invoke (proxy , args );
241246 }
242247
243- @ Override
248+
249+ @ Override
244250 protected Object serializableProxy () {
245251 return new SerializableProxy (
246252 getEntityName (),
Original file line number Diff line number Diff line change 1919import java .lang .reflect .InvocationTargetException ;
2020
2121import org .apache .commons .beanutils .PropertyUtils ;
22+ import org .codehaus .groovy .grails .orm .hibernate .cfg .GrailsHibernateUtil ;
2223import org .codehaus .groovy .grails .support .proxy .ProxyHandler ;
2324import org .hibernate .Hibernate ;
2425import org .hibernate .collection .AbstractPersistentCollection ;
@@ -79,7 +80,10 @@ public Object unwrapProxy(final HibernateProxy proxy) {
7980 if (lazyInitializer .isUninitialized ()) {
8081 lazyInitializer .initialize ();
8182 }
82- return lazyInitializer .getImplementation ();
83+ final Object obj = lazyInitializer .getImplementation ();
84+ if (obj != null )
85+ GrailsHibernateUtil .ensureCorrectGroovyMetaClass (obj ,obj .getClass ());
86+ return obj ;
8387 }
8488
8589 public HibernateProxy getAssociationProxy (Object obj , String associationName ) {
You can’t perform that action at this time.
0 commit comments