NHibernate's Save/SaveOrUpdate() has nothing do to with transaction
handling. IF those methods result in immediate SQL and there is no
surrounding transaction, the database server itself will use automatic
transactions for each batch - which may result in a partially updated
database.

This is different compared to SaveChanges() from Entity Framework, which
will create a TransactionScope internally - this is possibly only because
Entity Framework has no automatic flushing of dirty state to the database.

/Oskar



2012/10/23 gleb Chermennov <thebitteren...@gmail.com>

> I thought when doing session.Save/session.SaveOrUpdate, transaction
> management is handled by NHibernate (e.g. it will commit if no exceptions
> and rollback otherwise). Am I wrong?
>
> вторник, 23 октября 2012 г., 15:48:45 UTC+4 пользователь Oskar Berggren
> написал:
>>
>> Just to be clear, I did NOT imply that have to use TransactionScope.
>> Specifically, if you do use it, for best results you should still use the
>> NHibernate transaction also.
>>
>> /Oskar
>>
>>
>>
>>  2012/10/23 graffitiMSX <rudolf...@gmail.com>
>>
>> Sorry, I wrote "Transaction Scope" when I meant to say only "The Scope of
>>> one Transaction".
>>>
>>> I am getting the session that is already open, and not disposing it. I
>>> will rewrite the code and try to use correctly the TransactionScope, and
>>> also dispose the session right after the Transaction.
>>>
>>> Thanks
>>>
>>> Rudolf
>>>
>>> Em terça-feira, 23 de outubro de 2012 09h15min11s UTC-2, Oskar Berggren
>>> escreveu:
>>>>
>>>> I don't see any TransactionScope. Where are you disposing the session?
>>>> Be aware that if you continue to use the session instead of disposing or
>>>> clearing it (or open a new transaction) immediately after rollback, you run
>>>> the risk of the session performing SQL INSERT/UPDATE outside of the
>>>> transaction. A session should be discarded "quickly" when an error occurs.
>>>>
>>>> Note that you don't need to rollback explicitly as long as you ensure
>>>> the transaction is disposed. It will then rollback unless it has been
>>>> expressly committed.
>>>>
>>>> /Oskar
>>>>
>>>>
>>>>
>>>> 2012/10/23 graffitiMSX <rudolf...@gmail.com>
>>>>
>>>>> Hi folks, I am doing several operations inside a Transaction Scope,
>>>>> when a failure occurs then it is redirected to the Rollback but the
>>>>> pre-failure saves are committed to db.
>>>>>
>>>>> My code is essentialy this:
>>>>>
>>>>> if (!_session.IsOpen) _session.SessionFactory.**OpenSe**ssion();
>>>>> using (_session.BeginTransaction())
>>>>> {
>>>>> try
>>>>>  {
>>>>>  Remittance remittance = new Remittance();
>>>>> ...
>>>>> _remittanceDao.SaveOrUpdate(**re**mittance);
>>>>>  TripSent tripSent = new TripSent();
>>>>> try
>>>>> {
>>>>> TripSent tripSent = CreatTripSent();
>>>>>  _tripSentDao.Save(tripSent);
>>>>> }
>>>>> catch (Exception ex)
>>>>>  {
>>>>>  throw new Exception(String.Format("Erro criando TripSent com índice
>>>>> {0}", i), ex);
>>>>> }
>>>>> Entity.TransactionFile eTransactionFile = new Entity.TransactionFile();
>>>>>  ...
>>>>> _transactionFileDao.**SaveOrUpda**te(eTransactionFile)**;
>>>>> _session.Transaction.Commit();
>>>>>  processOk = true;
>>>>> }
>>>>> catch
>>>>> {
>>>>>  _session.Transaction.Rollback(****);
>>>>> throw;
>>>>> }
>>>>> }
>>>>>
>>>>> The error is occuring in the line _tripSentDao.Save(**tripSen**t);
>>>>> and, even after the Rollback I check the DB and the
>>>>> _remittanceDao.SaveOrUpdate(**re**mittance); is there.
>>>>>
>>>>> Any help?
>>>>>
>>>>> Rudolf
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Fluent NHibernate" group.
>>>>> To view this discussion on the web visit https://groups.google.com/d/*
>>>>> *ms**g/fluent-nhibernate/-/**4ONRBEks**w98J<https://groups.google.com/d/msg/fluent-nhibernate/-/4ONRBEksw98J>
>>>>> .
>>>>>  To post to this group, send email to fluent-n...@**googlegroups.com.
>>>>> To unsubscribe from this group, send email to fluent-nhibern...@**
>>>>> googlegroups**.com.
>>>>>
>>>>> For more options, visit this group at http://groups.google.com/**group
>>>>> **/fluent-nhibernate?hl=en<http://groups.google.com/group/fluent-nhibernate?hl=en>
>>>>> .
>>>>>
>>>>
>>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Fluent NHibernate" group.
>>> To view this discussion on the web visit https://groups.google.com/d/**
>>> msg/fluent-nhibernate/-/**jyOcjU-FBN8J<https://groups.google.com/d/msg/fluent-nhibernate/-/jyOcjU-FBN8J>
>>> .
>>>
>>> To post to this group, send email to fluent-n...@**googlegroups.com.
>>> To unsubscribe from this group, send email to fluent-nhibern...@**
>>> googlegroups.com.
>>> For more options, visit this group at http://groups.google.com/**
>>> group/fluent-nhibernate?hl=en<http://groups.google.com/group/fluent-nhibernate?hl=en>
>>> .
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Fluent NHibernate" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/fluent-nhibernate/-/V5KKDY_5D8wJ.
>
> To post to this group, send email to fluent-nhibernate@googlegroups.com.
> To unsubscribe from this group, send email to
> fluent-nhibernate+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to