-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate lazy instantiation problem
PostPosted: Mon Aug 08, 2005 2:21 pm 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
Hello

I get an error that reads "Hibernate lazy instantiation problem". What does this mean? I am reading from one table and inserting & deleting to/from 3 other tables. Any ideas? Thanks!

Hibernate version:
2.1.8

Code between sessionFactory.openSession() and session.close():
public void convert()
{
Session session = null;
Transaction tx = null;
T_psched currentPsched = null;

try
{
session = SessionManager.getSessionFactory().openSession();
tx = session.beginTransaction();

String previousStudy = "-1";
int previousPatid = -1;
int numDeleted = 0;

// get all the psched objects, ordered
Query pidQuery = session.getNamedQuery("allPatientsOrdered");
Iterator pschedIter = pidQuery.iterate();

// scan through each T_psched object
while(pschedIter.hasNext())
{
currentPsched = (T_psched) pschedIter.next();

if ((!(currentPsched.getT_pschedID().getStudy().equals(previousStudy))) ||
(currentPsched.getT_pschedID().getStudy().equals(previousStudy) &&
(currentPsched.getT_pschedID().getPatid() != previousPatid)))
{
// we have a different study/patid than previous iteration
// so save this study/patid do compare against on the next iteration
// and clear of legacy tables for this study/patid

previousStudy = new String(currentPsched.getT_pschedID().getStudy());
previousPatid = currentPsched.getT_pschedID().getPatid();

Object values[] = new Object[2];
values[0] = currentPsched.getT_pschedID().getStudy();
values[1] = new Integer(currentPsched.getT_pschedID().getPatid());
Type types[] = new Type[2];
types[0] = Hibernate.STRING;
types[1] = Hibernate.INTEGER;

// delete all the ddmiss objects for the current study/patid
numDeleted = session.delete("from T_ddmiss as ddmiss where ddmiss.t_ddmissID.study = ? and ddmiss.t_ddmissID.patid = ?",
values, types);
tx.commit();

// delete all the pat_sch objects for the current study/patid
numDeleted = session.delete("from T_pat_sch as pat_sch where pat_sch.t_pat_schID.study = ? and pat_sch.t_pat_schID.patid = ?",
values, types);
tx.commit();

// delete all the ddcmpl objects for the current study/patid
numDeleted = session.delete("from T_ddcmpl as ddcmpl where ddcmpl.t_ddcmplID.study = ? and ddcmpl.t_ddcmplID.patid = ?",
values, types);
tx.commit();
}

if (currentPsched.getComp() == 2)
{
// translate psched object into ddmiss object & save it
convertAndSaveDDMISS(currentPsched);
}

if ((currentPsched.getReq() == 1) && (currentPsched.getComp() != 1))
{
// translate psched object into pat_sch object & save it
convertAndSavePAT_SCH(currentPsched);
}

if (currentPsched.getComp() == 1)
{
// translate psched object into ddcmpl object & save it
convertAndSaveDDCMPL(currentPsched);
}
}
}
catch (Throwable e)
{
if(tx!=null && session!=null && session.isOpen())
{
try
{
tx.rollback();
}
catch (HibernateException he)
{
logger.error(he.getMessage(), he);
}
}

logger.fatal("General Exception", e);

if (currentPsched != null)
logger.info(currentPsched.toString());

logger.info(Constants.programName + " Ended");
SessionManager.disconnect();
System.exit(1);
}
finally
{
try
{
if (session.isOpen())
{
session.close();
session = null;
}
}
catch (HibernateException he)
{
logger.error(he.getMessage(), he);
}
}
}

Full stack trace of any exception that occurs:
com.smurf.common.delinquency.legacyConverter.convertDCFS.ConvertDCFS.convert(ConvertDCFS.java:189)
General Exception

net.sf.hibernate.LazyInitializationException: Hibernate lazy instantiation problem
at net.sf.hibernate.impl.IteratorImpl.next(IteratorImpl.java:133)
at com.smurf.common.delinquency.legacyConverter.convertDCFS.ConvertDCFS.convert(ConvertDCFS.java:120)
at com.smurf.common.delinquency.legacyConverter.convertDCFS.ConvertDCFS.main(ConvertDCFS.java:81)
Caused by: ca.edbc.util.EdbcEx: No open cursor exists matching the requested ID.
at ca.edbc.jdbc.EdbcObj.readResults(EdbcObj.java:782)
at ca.edbc.jdbc.RsltFtch.load(RsltFtch.java:353)
at ca.edbc.jdbc.RsltCurs.load(RsltCurs.java:245)
at ca.edbc.jdbc.EdbcRslt.next(EdbcRslt.java:562)
at net.sf.hibernate.impl.IteratorImpl.postNext(IteratorImpl.java:85)
at net.sf.hibernate.impl.IteratorImpl.next(IteratorImpl.java:127)
... 2 more
08/08/2005 13:46:34 - INFO
com.smurf.common.delinquency.legacyConverter.convertDCFS.ConvertDCFS.convert(ConvertDCFS.java:192)
com.smurf.common.delinquency.legacyConverter.tables.T_psched@4a6416f9

Name and version of the database you are using:
Ingres II


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 3:36 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Can you narrow this down to the actual line of Java that is causing the problem? Meanwhile, check to see if this line is being fired after the session has been closed.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 9:22 am 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
The program dies on this line:

currentPsched = (T_psched) pschedIter.next();

I don't believe that the session is closed. If it matters, I'm using the Hibernate Synchronizer Eclipse plugin. So there is some auto-generated code that I'm not overly familiar with. But I don't think any of the auto-generated code is the problem, because it isn't related to the call to next(), and the code that executes right before the call to next() is executed like 75 times in the loop without any problems. The database record that next() attempts to fetch also looks fine to me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.