ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephane Bailliez <sbaill...@apache.org>
Subject Serialization issue due to lazy-loading
Date Tue, 21 Jun 2005 16:29:25 GMT

I came across a slightly annoying issue a couple of minutes ago with 

For instance I'm serializing data over the network that have cglib 
instrumented classes (relations)

When lazyloading is enabled (default), it could seem obvious that it 
does not make sense to serialize your data. You could well have 
bazillions of objects, yet this is what lazy loading is all about 

Yet it is not always true.
You may know, that your relationships are not in the form 1:bazillion 
but more like 1:4 (replace 4 by your favorite 'less than 10' number) 
with very lightweights objects .

To workaround this, you can AFAIK:

1) disable applicationw-wide lazy loading via <settings/> (big side-effect)

2) implements your own serialization mechanism (annoying)

At the moment I did (2), where I'm basically doing:

class Parent {
    transient ArrayList children = new ArrayList();
    ... serializable fields...


     private void writeObject(ObjectOutputStream out) throws IOException {
         ArrayList list = new ArrayList(children);

     private void readObject(ObjectInputStream in) throws 
ClassNotFoundException, IOException {
         children = (ArrayList)in.readObject();

Yet, I was wondering if it would make sense to fine-grained control over 
the lazy-loading. For instance, having a per-statement lazy-loading flag 
where dependent requests (like in the case of n+1 selects) would inherit 
this flag.

Just some thoughts straight without thinking too much.
Any comments ?


View raw message