I'm moving a resulset from an Iterator into a Collection of Beans.
Code:
public Collection daoIteratorToBeanCollectionHoch(Iterator iterate) {
Collection dst = new Vector();
for (; iterate.hasNext(); ) {
Rechnung rech = (Rechnung) iterate.next();
ReportingBean_hoch rep = fillBean(rech);
dst.add(rep);
}
return dst;
}
private ReportingBean_hoch fillBean(Rechnung rech) {
ReportingBean_hoch rep = new ReportingBean_hoch();
if (rech.getLieferant() != null) {
rep.setLief_bezeichnung(rech.getLieferant().getBezeichnung());
rep.setLief_fibuKonto(rech.getLieferant().getFibuKonto());
}
if (rech.getMandant() != null) {
rep.setMand_bezeichnung(rech.getMandant().getBezeichnung());
rep.setMand_mdNr(rech.getMandant().getMdNr());
}
rep.setRech_barcode(rech.getBarcode());
rep.setRech_bruttoBetrag(rech.getBruttoBetrag());
rep.setRech_buchtext(rech.getBuchtext());
rep.setRech_eigeneBelegNummer(rech.getEigeneBelegNummer());
rep.setRech_rechnungsDatum(rech.getRechnungsDatum());
rep.setRech_rechnungsNummer(rech.getRechnungsNummer());
rep.setRech_skonto_netto(rech.getZkTageNetto());
return rep;
}
public Collection getReportRechAlle(HashMap params) {
sql = sqlSelectFieldsHoch + "from Rechnung r";
Iterator iterate = getHibernateTemplate().find("from Rechnung r").iterator();
Collection col = daoIteratorToBeanCollectionHoch(iterate);
return col;
}
So far so good, but when I use the "normal" way
Code:
getHibernateTemplate().iterate("from Rechnung r");
in the Method getReportRechAlle I get a "LazyInitializationException"
Trace:Code:
net.sf.hibernate.LazyInitializationException: Hibernate lazy instantiation problem
at net.sf.hibernate.impl.IteratorImpl.next(IteratorImpl.java:133)
at com.achtg.fibunet.webreb.hibernate.dao.impl.ReportingHochDAOImpl.daoIteratorToBeanCollectionHoch(ReportingHochDAOImpl.java:44)
at com.achtg.fibunet.webreb.hibernate.dao.impl.ReportingHochDAOImpl.getReportRechAlle(ReportingHochDAOImpl.java:91)
at com.achtg.fibunet.webreb.test.dao.ReportingHochDAOTest.testGetReportRechAlle(ReportingHochDAOTest.java:43)
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:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.SQLException: Invalid state, the ResultSet object is closed.
at net.sourceforge.jtds.jdbc.JtdsResultSet.checkOpen(JtdsResultSet.java:295)
at net.sourceforge.jtds.jdbc.JtdsResultSet.next(JtdsResultSet.java:555)
at net.sf.hibernate.impl.IteratorImpl.postNext(IteratorImpl.java:85)
at net.sf.hibernate.impl.IteratorImpl.next(IteratorImpl.java:127)
... 18 more
I can't see what may be wrong, anyone an idea?
Thank you!