Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

session.BeginTransaction() and transaction.Commit()

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
       transaction.Commit();
    }
  }

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!

like image 965
inutan Avatar asked Oct 27 '09 10:10

inutan


1 Answers

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

Read this article by Ayende Rahien.

like image 190
o.k.w Avatar answered Sep 29 '22 21:09

o.k.w