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

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

问题描述

我正在看ayende博客 http://ayende.com/blog/3946/关于NHibernate并发的nhibernate-mapping-concurrency ,我仍然不太清楚何时使用.看来这是解决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.

任何人都可以向我解释您将在哪种情况下使用以及为什么吗?

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

谢谢.

推荐答案

NHibernate 乐观并发控制时,请使用nofollow noreferrer>版本.如果未启用乐观并发控制并锁定您的应用程序,则将使用最后一次提交获胜"策略.如果两个事务大致同时修改同一对象,则您的用户可能会遇到丢失更新的情况.更合适的策略称为首次提交获胜".在这种情况下,第二笔交易将失败,并显示如下错误:某人已提交 修改您将要提交的数据.您一直在使用过时的 数据.请使用新数据重新开始对话.

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.

来自使用Hibernate的Java持久性:

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< version&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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