In reality, you won't actually wrap transactions around every Save call as
you have demonstrated here (that is actively NOT recommended, actually.)
It's much preferable to push the transaction much higher up-for instance, to
set up your transaction at the page request level as an HTTPModule, so your
saves are committed and transaction is closed when the request is
finished-making the actions in the request a single unit of work.  Besides
having a single, longer-running transaction, which is more efficient, it
means you won't have to worry about wrapping things in transactions
elsewhere in your code. If you're doing a desktop app, the recommendation is
generally similar in concept, but you might be using something like user
tasks for your units of work rather than the HTTP request.  There are
frameworks out there that others have written that should be able to help
get your infrastructure set up...Rhino Commons and Burrow are two that I can
think of off the top of my head.

Hope that helps!




On Tue, Mar 10, 2009 at 6:57 AM, graphicsxp <[email protected]>wrote:

>
> well i think i found the answer by myself, nhibernate only persist
> entities when comit is  called.  Correct me if I'm wrong.....
>
> On 10 mar, 11:47, graphicsxp <[email protected]> wrote:
> > Hello,
> >
> > I have a very strange problem but maybe it's just that I'm not so
> > experienced with nHibernate.
> >
> > I want to persist my entity so I call the .save() method like this :
> >
> >         _session.Save(pCutting);
> >
> > but it is not saved and when using log4net i can see there;s no update
> > statement...
> >
> > Now if I use a transaction to save the same entity :
> >
> >  ITransaction tx = null;
> >
> >       try
> >       {
> >         tx = _session.BeginTransaction();
> >         _session.Save(pCutting);
> >         tx.Commit();
> >       }
> >       catch (Exception e)
> >       {
> >         tx.Rollback();
> >         throw e;
> >       }
> >
> > That works, the update statement is generated on the Commit line.
> >
> > Why is that ? I don't want to use transactions all the time...
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to