Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cancel a hibernate query

Tags:

hibernate

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!

like image 364
alice Avatar asked Dec 11 '09 14:12

alice


People also ask

How does Hibernate Query work?

Hibernate is a Java framework that makes it easier to create database-interactive Java applications. In HQL, instead of a table name, it uses a class name. As a result, it is a query language that is database-independent. Hibernate converts HQL queries into SQL queries, which are then used to perform database actions.

How do I run a normal SQL query in hibernate?

In hibernate, you can execute your native SQL queries using the Session. createNativeQuery() method. Execute simple and complex native SQL query in hibernate application. Map native SQL query result to an @Entity object.


1 Answers

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.

like image 76
Aaron Digulla Avatar answered Sep 21 '22 14:09

Aaron Digulla