Hi Dmitry,
 
thanks for the answer. Unfortunatelly i cannot use your suggestion - in that case all objects in the collection will be loaded from database. The result will be the same if i will not use lazy="true" at all :).  Another solution for that - to implement my own RelationCollection and copy in a setter method all ids from Castor RelationCollection to it. Now i m thinking about not to close the transaction on the first stage, but i afraid about deadlocks :(.
 
Denis.
----- Original Message -----
Sent: Friday, December 06, 2002 2:13 PM
Subject: Re: [castor-dev] Lazy loading with long transaction

Hi Denis,
I faced the same problem. Apparently it's implementation feature: transaction closing invalidates result set. The workaround is to copy all the elements from castor collection into your own collection explicitly while transaction is open.
 
    db.begin();
    master = (Master)db.load(...);
//  copying code here
//  ...............
    db.commit();
    db.close()
 
Avoid transaction timeouts on large collections ))
 
regards
 
Dmitry Vereshchagin
----- Original Message -----
Sent: Wednesday, December 04, 2002 3:58 PM
Subject: [castor-dev] Lazy loading with long transaction

Hi folks,
 
does anyone managed to use a lazy loading feature with long transactions? I do have a biderectional 1:N relationship between Master and Detail objects.
My mapping file is:
 
  <class name="Master" identity="id" access="shared" key-generator="IDENTITY">
    ...
    <field name="details" type="Detail" lazy="true" collection="collection">
      <sql many-key="MasterID" />
    </field>
  </class>
  <class name="Detail" identity="id" key-generator="IDENTITY">
    ...
    <field name="master" type="Master" >
      <sql name="MasterID" />
    </field>
  </class>
i'm loading a master object in short transaction and close it just after master object was loaded, so master.getDetails method will give me a RelationCollection with only detail identities loaded.
    ...
    db.begin();
    master = (Master)db.load(...);
    db.commit();
    db.close()
    ...
    Collection list = master.getDetails();
    Iterator itr = list.iterator();
    while (itr.hasNext()) {
      Object o = itr.next();   // <--- this line gets an error
      System.out.println(o);
    }
 
And, when i trying to go through the details collection it gives me an error: "Transaction is closed!":

java.lang.RuntimeException: Transaction is closed!
 at org.exolab.castor.persist.RelationCollection$IteratorImp.lazyLoad(Unknown Source)
 at org.exolab.castor.persist.RelationCollection$IteratorImp.next(Unknown Source)
  ...
 
Any ideas how to avoid that problem?
 
Thanks, Denis.
 

Reply via email to