Thanks Lothan!
NH examples code I think follow this pattern:
using( var session = sessionFactory.CreateSession() )
using( var tx = session.BeginTransaction() ) {
var entity = new { Name = "John };
session.Save(entity)
session.Flush()
}
Behavior wise is the following any different (apart from it being
unreadable)
using( var session = sessionFactory.CreateSession() )
var entity = new { Name = "John }
session.Save(entity)
entity.Name = "Jane"
using( var tx = session.BeginTransaction() ) {
session.Flush()
tx.Commit()
}
}
Is a NH transaction same as a DB transaction?
Ajai
On Feb 16, 5:09 pm, "Lothan" <[email protected]> wrote:
> Someone please correct me if I'm wrong, but as far I am aware you need to
> explicitly call session.Flush() to flush the session if you're using
> FlushMode.Never.
>
> The way I look at it (and this may be technically incorrect) is that calling
> session.Save(...) basically marks the entity (or entity graph) for
> persistence. When you call transaction.Commit(), NHibernate decides whether
> or not to automatically flush persistence changes to the database based on
> flush mode. If you set FlushMode.Never, you're telling NHibernate that you
> are taking explicit responsibility to tell NHibernate when to flush the
> cache.
>
> --------------------------------------------------
> From: "ajaishankar" <[email protected]>
> Sent: Tuesday, February 16, 2010 4:43 PM
> To: "nhusers" <[email protected]>
> Subject: [nhusers] totally confused about transactions and session flush
>
> > Hi
>
> > I have always heard a NHibernate transaction != DB transaction.
>
> > So what exactly is it?
>
> > This is the behavior I am seeing:
>
> > Say I have a FlushMode of Never, when I begin a transaction, make some
> > changes and then commit - the updates do NOT get saved to the DB.
>
> > But when I have a FlushMode of Auto, it is saved to DB when I commit
> > the transaction.
>
> > Also the following link says:
>
> > NH 2.1https://www.hibernate.org/407.html#A15
>
> > "ISession.Transaction is always active - Unlike previous NHibernate
> > versions, as soon as this transaction is committed, a new transaction
> > is associated with the session"
>
> > What does this mean?
>
> > Somebody please prevent me from going insane! :-)
>
> > Ajai
>
> > --
> > 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.
--
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.