The whole point of using transactions is so that you can group multiple
changes into one unit, and make sure that it's either completed entirely,
or nothing at all.

You should not put transaction handling in every little method, as that
leads to the problem you know have - that usefulness of transactions has
been lost.

Transactions should be handled more top-level, where the scope of the
entire work unit is known.

If you have committed, it's committed. The database will have done its work
in securing the data. The only thing you can do in this case is to perform
a compensating change to undo the previous change. That is something you
have to write code for.

And then you have to ask yourself: what will I do if I can only undo half
of the changes (due to a new error)...

/Oskar
Den 27 jun 2014 18:30 skrev "WildMind" <[email protected]>:

>
>
> Hi,
>
>
> I have the following code all over many files in my data acces layer. The
> problem, the user calls the Save or SaveOrUpdate calls, then Commit for
> several different tables. If an exception is thrown after a few successful
> save transaction, only a partial save is successful and the exception will
> halt save transaction from saving the rest of the tables.
>
> Question: If the code is written like the following, If there is an
> exception thrown after a few save & commit, How to Rollback on successful
> Save transactions when a error occurred on the 3rd table save?
>
> Thanks and greatly appreciate
>
>
>
>
> ISession session = NHibernateSessionManager.GetCurrentSession();
>
>
> using (ITransaction tx = session.BeginTransaction())
>
> {
>
> try
>
> {
>
> session.Save(prn);
>
> tx.Commit();
>
> }
>
> catch (Exception)
>
> {
>
> tx.Rollback()
>
> throw;
>
> }
>
> }
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to