什么时候使用 Nhibernate <版本>? [英] When to use Nhibernate &lt;version&gt;?

查看:18
本文介绍了什么时候使用 Nhibernate <版本>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在看 ayende 博客 http://ayende.com/blog/3946/nhibernate-mapping-concurrency 关于 NHibernate 并发,我还是不太清楚什么时候用.这似乎是解决 StaleObjectException 的解决方案.

I was looking at ayende blog http://ayende.com/blog/3946/nhibernate-mapping-concurrency about NHibernate concurrency and i still not very clear when to use . It seems like it is a solution to solve StaleObjectException.

谁能向我解释一下您将在什么情况下使用 a 以及为什么?

Can anyone explain to me in what scenario you will use a and why ?

谢谢.

推荐答案

NHibernate Version 用于实现乐观并发控制.不启用乐观并发控制和锁定您的应用程序将使用最后提交获胜"策略.如果两个事务大致同时修改同一个对象,您的用户可能会遇到更新丢失的情况.更合适的策略称为首次提交获胜".在这种情况下,第二个事务将失败并显示如下错误:有人已经提交对您即将提交的数据的修改.你一直在使用陈旧的数据.请使用新数据重新开始对话.

NHibernate Version is used when you want to implement Optimistic concurrency control. Without enabling Optimistic concurrency control and locking your application will use "Last commit wins" strategy. Your users may experience lost updates if two transactions are modifying the same object at roughly the same time. The more appropriate strategy is called "First commit wins". In this scenario second transaction will fail with an error that would say something like: Somebody already committed modifications to the data you’re about to commit. You’ve been working with stale data. Please restart the conversation with fresh data.

来自 Java 持久化与 Hibernate:

Hibernate 提供自动版本控制.每个实体实例都有一个版本,可以是数字或时间戳.Hibernate 增加一个对象修改时的版本,自动比较版本,并在检测到冲突时抛出异常.因此,你将此版本属性添加到所有持久实体类中启用乐观锁.... 版本号只是一个计数器值——它没有任何有用的语义价值.实体表上的附加列由您的 Hibernate 应用程序使用.请记住,访问同一数据库的所有其他应用程序都可以(并且可能应该)也实现乐观版本控制并使用相同的版本栏.

Hibernate provides automatic versioning. Each entity instance has a version, which can be a number or a timestamp. Hibernate increments an object’s version when it’s modified, compares versions automatically, and throws an exception if a conflict is detected. Consequently, you add this version property to all your persistent entity classes to enable optimistic locking. ... The version number is just a counter value—it doesn’t have any useful semantic value. The additional column on the entity table is used by your Hibernate application. Keep in mind that all other applications that access the same database can (and probably should) also implement optimistic versioning and utilize the same version column.

这篇关于什么时候使用 Nhibernate <版本>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆