-->

How do I get hibernate to generate Oracle's FO

2020-08-04 10:35发布

问题:

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.