I would like to have an option to limit all Spring jpa queries to a certain time limit. If a query takes longer than the specified limit it should be cancelled. From what I saw this can be achieved by using javax.persistence.query.timeout and since I am in a Spring context:
spring:
jpa:
properties:
javax.persistence.query.timeout: 10000
This should limit all queries executed from spring repositories to 30 seconds, but it's not working. This repository method takes 20 seconds:
@Query(value = "select count(*) from pg_sleep(20)", nativeQuery = true)
int slowQuery();
I tried it with Postgresql 9.6.11 and with Postgresql 10.5.
Is there some problem with these Postgres versions? Is there any other way to achieve the query execution timeout?
5.4.10.FinalAvailableSettings.LOG_SLOW_QUERY: docs.jboss.org/hibernate/orm/5.4/javadocs/org/hibernate/cfg/…5.4.10.Final