Take the 2-minute tour ×

I am new to Nhibernate, so my query may seem trivial to you.

We generally embed data operation code inside

  using (var session = sessionFactory.OpenSession())
    using (var transaction = session.BeginTransaction())
       ...Code for CRUD operations

Because we generally BeginTransaction/Commit/Rollback for saving/updating/deleting data,

I wonder if BeginTransaction() and Commit() are required even if I am retriving data using session.Get<T>(id); or session.CreateCriteria<T>().List();

Please guide.

Thank you!

share|improve this question

2 Answers 2

up vote 4 down vote accepted

No, you can't do data retrieval without transaction; all NH operations are transaction-centric.

Read this article by Ayende Rahien.

share|improve this answer
But doesn't he say that you should use transactions for every operation in NH? Why do you say "No"? –  Egor Pavlikhin Oct 27 '09 at 10:44
@HeavyWave: I meant "No, you can't do that without transaction", guess I read the line wrongly. –  o.k.w Oct 27 '09 at 12:11

You should always use transactions in quieries. Not only for the perfomance but also for concurrency reasons, and Ayende says about it.

His Hibernate profiler shows and alert if you use queries not in transaction scope.

share|improve this answer

Your Answer


