Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How can I stop my query while the query is running (In JPA)

  Asked By: Geeske    Date: Jan 05    Category: Java    Views: 3086
  

How can I stop my query while the query is running (In JPA)

Share: 

 

16 Answers Found

 
Answer #1    Answered By: Herbert Weaver     Answered On: Jan 05

the query  is submitted to lower layers (JDBC, then DB) and most of the time of query execution is spend in DB layer so there is no way to stop  it in JPA layer.

 
Answer #2    Answered By: Richie Smith     Answered On: Jan 05

So how can I handle it in lower layers? My application has sent the query  (an event handles it by an operator) and suddenly the operator changes his/her decision and wants to stop  the operation(Query)?
How can I solve this problem? in any layer?

 
Answer #3    Answered By: Emma Brown     Answered On: Jan 05

I don't know any API that do that

there are some JDO implementations that support cancel in some special databases, but I don't know any standard way that works on all databases.

usually it is either a local DB and local driver, then queries usually block the program execution so you can't cancel.

if DB is on another machine, or connected through network layer the best you can is ignoring the wait for DB response in most cases.

 
Answer #4    Answered By: Willie Gomez     Answered On: Jan 05

There is no way to stop  runing query  in JPA.
When operator changes her mind, it will take
about some seconds and as you know this time
is enough for doing lots of things in machine world!

 
Answer #5    Answered By: Pravat Jainukul     Answered On: Jan 05

Any database has some api that get the current running  sqls, and also has some api that can stop  or kill current running sql or transactions. You can wirte a function or stored procedure in your database that get an sql id or transaction id and kill it, then in your program you can get the id of running sql that you want , using database api that you encapsulated it in a function or sp , and then kill it using another function call, you can do all of this using JPA, but you need to provide some usefull functions in your database,
in this case you call a function or sp using JPA insted of executing some other sql query  !

 
Answer #6    Answered By: Rocco Anderson     Answered On: Jan 05

I'm working with Intellij and I test all my query  with its SQL plugin. I know that this plugin works with JDBC, in lower level.
but you can handle your query with stop  button during the query is running.
So you think Intellj handles this problem with function or procedure or it sends another query or close the connection!!??
I dont know exactly what is it doing there?
Is there any idea about this situation?

 
Answer #7    Answered By: Scott Simmons     Answered On: Jan 05

First of all you need to check if it really stops the query  or just does not wait for the query. you can do it If you I know the database type (Oracle, MySQL, ...) I can let you know the proper command to check this.
If it really kills the query, Probably it gets and stores the Session ID when running  the query and submits the proper kill command (you have already selected the database type).

 
Answer #8    Answered By: Raju Srinivas     Answered On: Jan 05

Intellij, just closes the connection that created or kills the thread that created that connection, but this, does not mean that the database server closes the cursor or session,
the process in database server might continue and you must check your database's open cursors or open session to see the query  is running  or has stoped .

 
Answer #9    Answered By: Neil Turner     Answered On: Jan 05

my database is sqlserver, i have found a method in java.sql.Statement close(). i think it can be useful for me. but another question is :D How can I access to jdbc or better say lower lyer from JPA?

Is it possible ?

And I didnt test this situation but I think your process will be killed after you stop  the query  from your applicaton in Intellij but be sure i'll test and tell you the result

 
Answer #10    Answered By: Katrina Edwards     Answered On: Jan 05

JPA is Database independent
so you can't find such a method in JPA or other database independent technologies like it.

 
Answer #11    Answered By: Eddie Austin     Answered On: Jan 05

Maybe there are some ways to do it. I have not tried myself, but maybe this article is right about using
createNativeQuery

function:
www.oracle.com/.../vasiliev-jpql.html

 
Answer #12    Answered By: Antonio Dunn     Answered On: Jan 05

here's another suggestion, you might be able to get benefit from callbacks. and by that I mean if for instance this is a persist call, at the time of receiving postpersist, if user has initiated a cancel you then kick off a rollback of that persist,

I'm not quit sure if it works, but worth trying

 
Answer #13    Answered By: Holly Brown     Answered On: Jan 05

You can get the transaction or connection from entity manager in JPA, and close the statement or connection - if you want access directly to connection or statement - but be sure that, in some cases, witch the query  you have submited to database take a long time or cause a 'database blocking proccess' , closing the connection or statement via jdbc, might not result to closing the session in database server, you can test this by runnig a few concurrent application processes that send some bulk update, delete, select requests to database on a same table that has milions of records .

 
Answer #14    Answered By: Maliha Malik     Answered On: Jan 05

this doesn't always work for two reasons:

1) not all connection classes are thread safe

2) some connection classes allow you to run multiple statements (queries, updates,...) and closing the connection doesn't stop  the running  statement, but it only stops the thread/process managing connection on client side.

 
Answer #15    Answered By: Edward Jones     Answered On: Jan 05

There is someway(not a good one although) to let this be done. You can un-plug
database machine from power supply in the middle of query  execution!

 
Answer #16    Answered By: Lewis Welch     Answered On: Jan 05

It might be some some more ways to do it. it heavily depends on your database.
For example in Oracle there is a "Alter session kill process ..." command which you can embed in a stored procedure or directly calling using createNativeQuery.

 




Tagged: