When to use Nhibernate ?

后端 未结 1 402
暖寄归人
暖寄归人 2021-01-04 18:13

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

相关标签:
1条回答
  • 2021-01-04 18:28

    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.

    From Java Persistence with 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.

    0 讨论(0)
提交回复
热议问题