NHibernate - Only select, should I commit or rollback? NHibernate - Only select, should I commit or rollback? oracle oracle

NHibernate - Only select, should I commit or rollback?


First off, as you stated in your comment, you should always wrap code using NHibernate in a transaction.

I'm not sure about performance implications of rolling back vs committing, but I've found the idea of a read-only transaction (i.e., a transaction that always gets rolled back at the end of use) to be useful for two main reasons:

  1. Your code clearly indicates that work done inside of the read only transaction will not write anything down to the database, and
  2. You protect yourself from ghost updates caused by bad NHibernate mappings.

It does makes sense intuitively that rolling back a transaction would be a bit faster, but I can't find any (NHibernate) documentation to back that up.


Go ahead with committing the transaction, since you started it and there is no error. Even if you use it for select.

Have a look at this too : Should I commit or rollback a read transaction?


My knowledge into the ins and outs of DB stuff needs work but the way i thought transactions occured were more like 1 way than 2 way.

Meaning Update, Insert, Delete i am "Setting" the data, this is a transaction that may need a rollback etc.

Selecting data im "Getting" existing data, im not changing the data or effecting its values there for there is no need for a transaction to occur.

As far as i can tell when you refer to "Commit", i cant see that occuring on a select, as i said it appears there isnt a transaction taking place as im simply getting data, not changing its values.

Maybe someone with some concrete facts could advice better.