如何让 hibernate 生成 Oracle 的 FOR UPDATE WAIT 10 语法
我有一行这样的代码:
final Foo foo = (Foo)session.get( Foo.class, id, LockMode.UPGRADE );
这会生成一个SELECT .. FOR UPDATE
。
但是,我只愿意等待 10 秒来获取锁,并且我想要一个 SELECT .. FOR UPDATE WAIT 10 。我怎样才能让休眠来生成这个?
I have a line of code like this:
final Foo foo = (Foo)session.get( Foo.class, id, LockMode.UPGRADE );
This generates a SELECT .. FOR UPDATE
.
However, I'm only willing to wait for 10 seconds to obtain the lock and there for I would like a SELECT .. FOR UPDATE WAIT 10
. How can I get hibernate to generate this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案是使用
LockOptions
类使用SetTimeout()
而不是 LockMode。为此,我们升级到 Hibernate 3.6,却发现它对于 Oracle 来说已经损坏了。
The answer is to use the
LockOptions
class withSetTimeout()
rather than LockMode.For this, we upgraded to Hibernate 3.6 only to find it is broken for Oracle.
AFAIK,你不能。
但是您可以等待并设置 事务超时。这取决于当你没有获得锁时你想做什么。无论如何,当你回滚整个事情时,这并不重要。
另一种方式是不等待就加锁,一秒后尝试加锁,最多十次。这不太好,但无论如何都是某种解决方案。
AFAIK, you can't.
But you could just wait and set the transaction timeout. It depends on what you want to do when you don't get the lock. When you roll back the whole thing anyway, it doesn't matter much.
Another way is to lock without wait, and try to lock it a second later, up to ten times. This isn't nice but some kind of solution anyway.