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(?)
|
|