dsellers wrote:
Code:
using(ISession sess = GetASessionSomeHow())
using(ITransaction tr = sess.BeginTransaction())
{
try{
...do stuff [UnitOfWork?]
tr.Commit();
}catch (Exception ex){
tr.Rollback();
...do failure stuff
}
}
How does this look for a simple best practice use of ISession and ITransaction?
Hibernate documentation says:
Quote:
If you rollback the transaction you should immediately close and discard the current session to ensure that Hibernate's internal state is consistent.
Hibernate recommended exception handling:
Code:
Session sess = factory.openSession();
Transaction tx = null;
try {
tx = sess.beginTransaction();
// do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}
Isn't it also a best practice for NHibernate?
Shouldn't we also close session after transaction commit/rollback?