English 中文(简体)
NHibernate ISession. A. 更新
原标题:NHibernate ISession.Update

I have noticed, by using log4net, that when calling ISession.Update, it updates all the changed objects.
For example:


// Change 2 instances 
user1.IsDeleted = true;
user2.UserName = "Xyz";
// Call session.Update to update the 2 users
using (ITransaction transaction = session.BeginTransaction())
{
    Session.Update(user1); // This updates both user1 & user2
    transaction.Commit();
}
using (ITransaction transaction = session.BeginTransaction())
{
    Session.Update(user2); // Now there is no need for this
    transaction.Commit();
}

Is this the default behavior of NHibernate or has something to do with my mapping file?
Can I make NHibernate update one by one?

最佳回答

http://nhforge.org/doc/nh/en/index.html

Hibernate maintains a cache of Objects that have been inserted, updated or deleted. It also maintains a cache of Objects that have been queried from the database. These Objects are referred to as persistent Objects as long as the EntityManager that was used to fetch them is still active. What this means is that any changes to these Objects within the bounds of a transaction are automatically persisted when the transaction is committed. These updates are implicit within the boundary of the transaction and you don’t have to explicitly call any method to persist the values.

http://www.tobinharris.com/2007/2/3/nhibernate-faq”rel=“nofollow noreferer” 第2部分:

Q) Do I still have to do Save and Update inside transactions?

Save() is only needed for objects that are not persistent (such as new objects). You can use Update to bring an object that has been evicted back into a session.

NHibernate s auto (dirty eck) Update conduct:

I ve just discovered that if I get an object from an NHibernate session and change a property on object, NHibernate will automatically update the object on commit without me calling Session.Update(myObj)!

Answer: You can set Session.FlushMode to FlushMode.Never. This will make your operations explicit ie: on tx.Commit() or session.Flush(). Of course this will still update the database upon commit/flush. If you do not want this behavior, then call session.Evict(yourObj) and it will then become transient and NHibernate will not issue any db commands for it.

问题回答

这是一种缺省行为,因为届会是自治或竞争。

在这些案件中,要求交易。 A. 届会的流程图;更新所有持久性物体

因此,如果你取消电话会议。 更新后不会有任何差别

我能否逐个更新NHibernate?

是的。 如有可能,绝不会推迟举行届会。 我猜测你不需要利用Evict处理本案。





相关问题
why the session in iis automatically log out?

I used iis6, and when i called a function Directory.delete(), the all the session relate this website will be logged out. and i debugged the website, i found no exception. any one have ideas on this ? ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Can I get the size of a Session object in bytes in c#?

Is it possible to get the size(in bytes) of a Session object after storing something such as a datatable inside it? I want to get the size of a particular Session object, such as Session["table1"], ...

提供严格分类的出席会议物体

提供严格分类的与会机会的最佳方式是什么? 我正计划转而选择矩阵,这正在促使汇编者抱怨我的幻觉方案拟订方法......

PHP Session is not destroying after user logout

I m trying to create an authentication mechanism for my PHP Application and I m having difficulty destroying the session. I ve tried unsetting the authentication token which was previously set within ...

热门标签