SQL Server doesn't support the "SELECT FOR UPDATE" syntax, which is used by NHibernate for pessimistic locking. I read here on * descriptions of other alternatives (I liked the "SELECT WITH (...)" because it's quite close).
SQL Server不支持“SELECT FOR UPDATE”语法,NHibernate使用该语法进行悲观锁定。我在这里阅读其他备选方案的*描述(我喜欢“SELECT WITH(...)”,因为它非常接近)。
however NHibernate doesn't seem to support this syntax.
但NHibernate似乎不支持这种语法。
do you have a workaround for this? I believe this can be achieved by tinkering with NHibernate internals, but that's not cost effective for me at the moment (learning curve). I could also perhaps use a stored procedure with application locks, and access that from NHibernate. any other suggestions? (aside from always reading before writing...)
你有解决方法吗?我相信这可以通过修改NHibernate内部来实现,但这对我来说并不符合成本效益(学习曲线)。我也许也可以使用带有应用程序锁的存储过程,并从NHibernate访问它。还有其他建议吗? (除了在写作之前总是阅读...)
2 个解决方案
#1
NHibernate has a version strategy for optimistic locking:
NHibernate有一个乐观锁定的版本策略:
http://ayende.com/Blog/archive/2009/04/15/nhibernate-mapping-concurrency.aspx
#2
I don;t know much about NHibernate, but in SQL columns of ROWVERSION type are commonly used to implement optimistic locking. Example here
我不太了解NHibernate,但在ROWVERSION类型的SQL列中通常用于实现乐观锁定。这里的例子
#1
NHibernate has a version strategy for optimistic locking:
NHibernate有一个乐观锁定的版本策略:
http://ayende.com/Blog/archive/2009/04/15/nhibernate-mapping-concurrency.aspx
#2
I don;t know much about NHibernate, but in SQL columns of ROWVERSION type are commonly used to implement optimistic locking. Example here
我不太了解NHibernate,但在ROWVERSION类型的SQL列中通常用于实现乐观锁定。这里的例子