Hi,
I've a question regarding session closing. I need to perform a batch transaction several times (read data froma flat file and update the database).
Here's the code that updates the database.
public void update(IMessage accountMessage, String action)
throws HibernateException {
Session session = null;
Transaction tx = null;
try {
session = HibernateSession.currentSession();
tx = session.beginTransaction();
ProcessHandler acctUserLoaderLog = new
AcctUserLoaderLogHandler();
acctUserLoaderLog.load(accountMessage, action);
} catch (Exception e) {
logger.error("Error happened")
} finally
{
try {
if (tx != null)
tx.commit();
tx = null;
if (session != null){
session.close();
}
}
I call update method for every record I read from the file.
Should I call close session for every record. or call just once. Becuase as it is, it throws an exception 'Session already closed'
Thu Aug 25 11:31:52:186 CDT 2005 MM:ERROR net.sf.hibernate.HibernateException: Session is closed
net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3292)
net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:65)
net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
net.sf.hibernate.loader.Loader.list(Loader.java:1024)
net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
Thanks for your time
Ram
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: