I want JPA queries made by my Spring Boot application to a Postgres database to timeout after 5 seconds.
I have created this 20 seconds query to test timeouts:
@Query(value = "select count(*) from pg_sleep(20)", nativeQuery = true)
int slowQuery();
I've set the following properties in application.config:
spring.jpa.properties.javax.persistence.query.timeout=3000
javax.persistence.query.timeout=5000
But the query does not timeout after 3s or 5s (it still takes 20s to execute).
Strangely, if I annotate slowQuery with @Transactional(timeout = 10), it times out after 10s or so.
I would prefer not to annotate every query. I'm using JPA 2.0 and the Tomcat connection pool.
What magic is required to make the timeout work just by setting them in application properties file?