raqm
raqm

Reputation: 51

@Transactional with timeout is not working in Springboot Application for value other than 1 (timeout=1)

I am using spring-boot-starter-data-jpa from Spring Boot 2.0.2.RELEASE, using spring-data-jpa. DB is Oracle. JDK 1.8.

I am using @Transactional on top of a method that is calling a long-running query. When the transaction timeout is set to 1, the transaction is timing out within 1 second. When @Transactionnis to timeout > 1, there is no timeout exception. The query runs we get the response. Here is a snapshot of my code:

@Transactional(propagation = Propagation.REQUIRES_NEW, timeout = 5)
public List<Pojo> doStuff() {
    result = myRepository.findDetails(); -- This call long running native query
  ...
}

Strangely, this works when the app is run in debug mode and a breakpoint is kept at the call to repository method. I have tried the following

  1. javax.persistence.query.timeout with hint also did not timeout
  2. server.connection-timeout=3s - did not work
  3. spring.jpa.properties.javax.persistence.query.timeout=10 - did not work
  4. oracle.jdbc.ReadTimeout - works but does not timeout at the specified time.

If 100 is mentioned then it sometimes throws exception in 1 mins sometimes less/more. We are getting response from DB after 5 mins. We would like to timeout before that and send timeout response to the client.

Upvotes: 3

Views: 1664

Answers (0)

Related Questions