NHibernate 和 Rhino 存储库的奇怪保存行为
我在使用 NHibernate 时遇到了一些奇怪的行为。我正在从存储库中检索学习者列表,并根据需要更新它们,奇怪的是,当我保存第一个学习者时,对所有学习者所做的更改都被提交到数据库中。
[Transaction]
public void UpdateLearner(Learner learner)
{
//UnitOfWork.CurrentSession.Save(learner);
}
有什么想法吗?我没有启用缓存。我知道它与事务有关,因为即使对保存方法的调用被注释掉,更改也会保留下来。
这是我的映射:
<class name="Learner" table="ILR_Learner">
<id name="Id" column="ILRLearnerID">
<generator class="native" />
</id>
<property column="LastWarning" name="LastWarning" type="DateTime" />
<property column="Submitted" name="SuccessfulSubmission" type="DateTime" />
<join table="vwLearnerLSCUpload">
<key column="ILRLearnerID" foreign-key="ILRLearnerID"/>
<property column="Dog" type="DateTime" name="Dog"/>
</join>
<join table="Learner">
<key column="Id" foreign-key="ILRLearnerID"/>
<property column="Food" name="Food" type="String" length="20" />
</join>
</class>
I am experiencing some odd behaviour with NHibernate. I'm retrieving a list of Learners from a repository, updating them as necessary, the odd thing is when I save the first one, the changes made to all the learners are being commited to the database.
[Transaction]
public void UpdateLearner(Learner learner)
{
//UnitOfWork.CurrentSession.Save(learner);
}
Any ideas why? I dont have caching enabled. I know its something to do with the transaction as the changes get persisted even with the call to the save method commented out.
This is my mapping:
<class name="Learner" table="ILR_Learner">
<id name="Id" column="ILRLearnerID">
<generator class="native" />
</id>
<property column="LastWarning" name="LastWarning" type="DateTime" />
<property column="Submitted" name="SuccessfulSubmission" type="DateTime" />
<join table="vwLearnerLSCUpload">
<key column="ILRLearnerID" foreign-key="ILRLearnerID"/>
<property column="Dog" type="DateTime" name="Dog"/>
</join>
<join table="Learner">
<key column="Id" foreign-key="ILRLearnerID"/>
<property column="Food" name="Food" type="String" length="20" />
</join>
</class>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新实体时,会自动跟踪更改。因此,当提交事务时,所有更改的实体都会被持久化。无需致电:
请参阅此问题。
要禁用每个实体的更改跟踪,您必须从会话中逐出该实体:
要保留任何更改,您可以调用:
When updating entities, changes are tracked automatically. So when the transaction is committed all changed entities are persisted. No need to call:
See this Question.
To disable change tracking per entity you have to evict the entity from the session:
To persist any changes, you would then call: