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 !