When doing a Select in nhibernate I suppose a Rollback is faster than a Commit since neither NHibernate nor Oracle has to do any checks for if anything is updated.
But all examples I have found does a Commit after Selecting.
While if I use an implicit transaction the framework does a Rollback.
My question is about speed and resource use, not about architecture or coding stye.
( Now the ones who write nhibernate know way more about the innards of nhibernate than I do and they have chosen to make a Rollback on an implicit transaction with only Select. This might be to totally different reasons than I have (not committing must lead to a rollback being a possible reason). )
( There is also an architectural/psychological argument around what should happen in a possible future edit where someone decides to call an Update in the same code. Should the dev be surprised by a Rollback or should a misplaced Update surprise the users with a Commit? This discussion is not part of the main question. )
using (var session = Helper.SessionFactory.OpenSession())
{
using (var tran = session.BeginTransaction())
{
var ret = session.Query<Person>().Where(x => x.Id == id).Single();
tran.Rollback(); // <----- or commit?
return ret;
}
}
or should I call
tran.Commit();
?