How do I get hibernate to generate Oracle's FOR UPDATE WAIT 10 syntax

a 夏天 提交于 2019-12-10 00:10:47

问题


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?


回答1:


The answer is to use the LockOptions class with SetTimeout() rather than LockMode.

For this, we upgraded to Hibernate 3.6 only to find it is broken for Oracle.




回答2:


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.



来源:https://stackoverflow.com/questions/5320755/how-do-i-get-hibernate-to-generate-oracles-for-update-wait-10-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!