让我解释一下我的场景...
假设我有两个表:“路径”和“包”
路径表由“PathId”、“StartNode”、“EndNode”组成
包表由“StartNode”、“DestinationNode”、“Paths”组成,
我将编写一个程序,使用任何最短路径算法来计算将包从开始路由到目的地的路径。
为了确保在计算路径时路径设置不会更改,我相信我应该使用“SELECT * FROM Paths FOR SHARE”来获取共享锁。因此,在计算路径并提交事务之前,不得更改路径开始/结束,并且在任何时候 - 数据库中计算的路径始终有效。
问题是:我正在用 NHibernate 编写 C# 程序,如何获得共享锁?
我已经尝试过:
Session.QueryOver<Path>().Lock().Read.List()
但它没有发挥作用。
Session.CreateSQLQuery()
是唯一的解决方案吗?
Let me explain my scenario...
Say I have two table: "Paths" and "Packages"
Paths table is consists of "PathId" "StartNode", "EndNode"
Packages table is consists of "StartNode", "DestinationNode", "Paths"
I am going to write a program which compute the path that route a package from start to destination, using whatever shortest path algorithm.
In order to make sure the paths settings are not changing while I compute the path, I believe I should use "SELECT * FROM Paths FOR SHARE" to obtain a share lock. So until the paths are computed and transaction is committed, the path start/end must not be changed, and at any point - the computed paths in the database is always valid.
The question is: I am writing the program C# with NHibernate, how do i get a share lock?
I have tried:
Session.QueryOver<Path>().Lock().Read.List()
but it does not do the magic.
Is Session.CreateSQLQuery()
the only solution?
发布评论
评论(1)
据我所知,NHibernate 目前不支持 SELECT...FOR SHARE,但它支持 FOR UPDATE 和 FOR UPDATE NOWAIT(请参阅 锁定模式),这当然更严格,但它会起作用。
由于 NHibernate 是一个开源项目,您可以建议此增强功能,当然也可以实现它。
As far as I know NHibernate does not currently support SELECT...FOR SHARE, but it does support FOR UPDATE and FOR UPDATE NOWAIT (see lock modes), which is of course more strict, but it would work.
Since NHibernate is an open source project you may suggest this enhancement and of course implement it.