Spring JPA - transactional stored procedure for get-and-increment

Viewed 140

I have a MySQL stored procedure that:

  1. reads the numeric value of a (non-PK) column named current_tag_id
  2. increments the column
CREATE PROCEDURE GET_AND_INCREMENT(IN table_id BIGINT, out tag BIGINT)
BEGIN
    select current_tag_id INTO tag from my_table where id = table_id;
    update my_table set current_tag_id = current_tag_id + 1 where id = table_id;
END

Since I want this operation to be atomic, I have to wrap it into a transaction for my Spring Boot application.

My question is: should I wrap the MySQL stored procedure in a MySQL transaction (with BEGIN/COMMIT) or should I go with calling the stored procedure with Spring JPA in an @Transactional(isolation = Isolation.SERIALIZABLE) annotated method?

0 Answers
Related