alice
alice

Reputation: 71

How can I cancel a hibernate query

If a user presses the "search" button and then they decide to do "something else", we have to cancel an already running query.

We use Hibernate (and Oracle) as persistence solution. Hibernates Session interface provides a cancelQuery() method. After some testing, it seems that cancelQuery() has no effect.

Does anybody have some experience with this Session#cancelQuery() method?

Thank you!

Upvotes: 7

Views: 5074

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328744

It has an effect but with the Oracle JDBC driver, it just takes some time to happen. Just wait a minute or two.

If you can't wait, then move the cancel in a background thread (along with the session) and request a new Hibernate session in your main thread. You can't use the old session until cancelQuery() returns.

Upvotes: 7

Related Questions