Re-start mechanism for optimistic locking (spring data + JPA)

We decided to use optimistic locking in our web application to increase concurrency without using pessimistic locking.

We are now in search of solutions for retries.

We would like to have as little impact on our current code base as possible.

One solution we have seen on the Internet is to use a re-interceptor with an annotation to indicate a method that can be reusable.

The problem is that we would like to annotate methods that contain @Transactional annotation, but for some reason the interceptor does not repeat them. (The interceptor perfectly terminates transactional methods.)

So:

1) Are there alternatives to replay that will have minimal impact on our code?

2) Are there any documents \ tutorials for this solution?

3) Is it even possible to repeat the annotated @Transactional method?

Hurrah!

+4
source share
2 answers
+1
source

Announcement 3.

Spring Retry, transacted, ( ).

@Configuration
@EnableRetry
public class FooConfig {
     ...
}

@Retryable(StaleStateException.class)
@Transactional
public void doSomethingWithFoo(Long fooId){
    // read your entity again before changes!
    Foo foo = fooRepository.findOne(fooId);

    foo.setStatus(REJECTED)  // <- sample foo modification

} // commit on method end

@Transational(propagation = REQUIRED_NEW) .

0

Source: https://habr.com/ru/post/1526120/


All Articles