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