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 <javascript:>> > >> 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.**OpenSession(); >>>> using (_session.BeginTransaction()) >>>> { >>>> try >>>> { >>>> Remittance remittance = new Remittance(); >>>> ... >>>> _remittanceDao.SaveOrUpdate(**remittance); >>>> 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.**SaveOrUpdate(eTransactionFile)**; >>>> _session.Transaction.Commit(); >>>> processOk = true; >>>> } >>>> catch >>>> { >>>> _session.Transaction.Rollback(**); >>>> throw; >>>> } >>>> } >>>> >>>> The error is occuring in the line _tripSentDao.Save(**tripSent); and, >>>> even after the Rollback I check the DB and the _remittanceDao.SaveOrUpdate( >>>> **remittance); 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/** >>>> msg/fluent-nhibernate/-/**4ONRBEksw98J<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. >> >> To post to this group, send email to >> fluent-n...@googlegroups.com<javascript:> >> . >> To unsubscribe from this group, send email to >> fluent-nhibern...@googlegroups.com <javascript:>. >> 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 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.