I use Hibernate 3 Beta and have the following method to insert objects.
public synchronized long create(Persistable obj) throws IOException
{
long id = -1;
try {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
id = ((Long)session.save(obj)).longValue();
logger.warn("crea1");
tx.commit();
session.close();
logger.warn("crea2");
} catch(Exception ex) { throw new IOException("Error creating object:"
+ obj + "\r\n" + ex.toString()); }
return id;
}
This method works. If, however, I remove the two logging statements the execution results in:
"WARN - unclosed connection, forgot to call close() on your session?"
This is reproducible and happens for my update-method as well.
|