Does Select For update query in Db2 need Spring's @Transactional annotation

49 views Asked by At

Is Spring Transaction management needed if the SQL query running on Db2 database itself has the isolation level and locks specified.

For example, I have the following java method which has two SQL queries running on Db2 database. Queries are run using Spring jdbc template.

public List<String> method1(){
   //Runs query: select col1,col2 from mytable where col3=x for update with RS use and keep update locks
   //Runs SQL query: update mytable set col3=y where col1= <value fetched from above>
  return col2
}

Does this method need @Transactional annotation when the query is Select For Update With RS use and keep update locks.

The table mytable here has a list of jobs to be picked up by multiple instances of the same application and I want to avoid a single row being picked by two instances. Hence the keywords "with RS use and keep update locks".

So there are two questions:

  1. Is @Transactional needed on the method?
  2. Select for update with RS use and keep update locks - Is this going to make sure that a single record is not going to be picked up by multiple instances. Can there be deadlocks and if yes, how to avoid it?

Thanks.

0

There are 0 answers