-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: LazyInitializationException & session.clear()
PostPosted: Thu Jan 29, 2004 11:18 am 
Newbie

Joined: Thu Jan 29, 2004 11:03 am
Posts: 2
Hi!
I'm having troubles using collections defined as lazy.
I have a "for" cycle where I get results of a query
and try to obtain a collection. At the end of the for cycle
I put a session.clear() to evict all the objects I use.
When I pass through the query the second time and try
again to obtain the collection I get
a LazyInitializationException
It seems the session.clear() make unusable the
Lazy collection ... but in another application I've
used session.clear and lazy collections with success!

Here a sample of my code:

Code:
for (minId = 0; minId <= topId; minId = minId + stepId) {

                maxId = minId + stepId;

                mainQuery = mySession.createQuery("from table "
                    + "where id >= :minId and id <= :maxId) "                   
                    + "order by id asc");

                mainQuery.setInteger("minId",(int) minId);
                mainQuery.setInteger("maxId",(int) maxId);
                mainQuery.setCacheable(false);

                results = mainQuery.list().iterator();

                while (results.hasNext()) {
                     
                      row = (Object[])results.next();
                      results.remove();

                      myObj1 = (Obj1)row[0];
                      myObj2 = (Obj2)row[1];

                          if (myObj1.getObj3() != null) {

                              Iterator iter1 = myObj1.getObj3()).iterator();
                           }
                           
                 }
                 
        mySession.clear();
       
}


Thank you very much!

Kyato


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Fri Mar 26, 2004 12:33 am 
Regular
Regular

Joined: Sun Oct 26, 2003 9:02 pm
Posts: 90
Hi Kyato

I've been having the same problem. I need to eliminate the objects from session cache using session.evict or session.clear and after that I can't use lazy initialization. Have you found a workaround for this problem?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.