Hi,
I'm a Hibernate noobie. Typical Hibernate code I've seen so far might look like this:
Code:
public void save(MyBean myBean) throws Exception {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(myBean);
tx.commit();
session.close();
}
No one seems to use try/finally blocks to close the session if the save() call fails. Isn't this necessary??
Code:
public void save(MyBean myBean) throws Exception {
Session session = null;
Transaction tx = null;
try {
session = sessionFactory.openSession();
tx = session.beginTransaction();
session.save(myBean);
tx.commit();
}
finally {
if (session != null)
session.close();
}
}
Thanks in advance for any advice,
Eric