-->
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: Failed to lazily initialize a collection
PostPosted: Mon Aug 02, 2004 8:02 am 
Newbie

Joined: Wed May 12, 2004 3:17 pm
Posts: 11
dear all...

i m getting this kind of error while i get a Set of values from my persistent.
My Code Is :

Transaction tx = session.beginTransaction();
CabImpl cabImpl = new CabImpl();
Collection cabs = cabImpl.getCabs();
Iterator iterator = cabs.iterator();
Iterator iter = null;
while(iterator.hasNext()){
Cab cab = (Cab)iterator.next();
Set set = cab.getTripSheets();
iter = set.iterator();
TripSheet t = null;
while(iter.hasNext()) {
t = (TripSheet)iter.next();
System.out.println(t.getId() + " " + t.getDistance());
}
}


the Error is :

net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:214)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.iterator(Set.java:130)
at com.celestials.routing.cab.domain.TripSheetTest.testTripSheetTest(TripSheetTest.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:410)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:294)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:182)




but by giving explicitely like this i m getting the desired o/p.

Cab cab = (Cab) session.load(Cab.class, new Long(1));
Set set = cab.getTripSheets();
Iterator iter = set.iterator();
TripSheet t = null;
while(iter.hasNext()) {
t = (TripSheet)iter.next();
System.out.println(t.getId() + " " + t.getDistance());
}


My HBM File Pat is :
<set name="TripSheets"
table="Trip_Sheet"
lazy="true"
inverse="false">
<key column="Cab_Id"/>
<one-to-many
class="com.celestials.routing.cab.domain.TripSheet"/>
</set>


kind help in solving this is much appreciated...
anything needed from my part to find sol.
thanx in advance

-NewBie(?)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 8:14 am 
Newbie

Joined: Wed May 12, 2004 3:17 pm
Posts: 11
got it...! anyway thanx for all...

actually i have closed my seesion in my Implementation.
so i have to make the session live again to make it work.

while(iterator.hasNext()){
Cab cab0 = (Cab)iterator.next();
Cab cab = (Cab) session.load(Cab.class, cab0.getId());
Set set = cab.getTripSheets();
iter = set.iterator();
TripSheet t = null;
while(iter.hasNext()) {
t = (TripSheet)iter.next();
System.out.println(t.getId() + " " + t.getDistance());
}
}

-NewBie(!)


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.