views:

67

answers:

1

I am Serializing an object which has a deep hierarchy of objects.

After deserialization, i am able to access only those fields which were available in object before serialization. For rest, i get LazyInitializationException.

class A {
    List<B> objs
}

class B {
    C c
}

class C {
    D d
}

Initially, i used to get LazyInitializationException while accessing a.objs*.c Then i executed a loop before serialization: a.objs.each{it.c} Now I get LazyInitializationException at a.objs*.c.d and not a.objs*.c

How do I make sure that object fetches each reference from DB before serialization?

A: 

The only way I can think of is to walk through the object graph initializing any lazy collections you find.

The only other way is to use the mapping closure in each domain class to disable lazy loading.

Could you not refresh the object from the database after deserialization using the refresh() method?

leebutts
Aman Aggarwal