skip to Main Content

I am using Spring boot with Mysql. I have implemented Datasource and defined properties in application.xml file.

I have a long running query:

@Query(value - "select sleep(10)", nativeQuery=true)
public void test();

in JPA repository methods.

I want to implement query timeout here. I tried using @Transactional(timeout = <>) but I do not want to use that as I will have to do this for all DB methods. I want a global solution.

I also tried setting javax.persistance.query.timeout but I think mysql does not support the same. Any suggesstions on how to implement query timeout with mysql and spring boot?

2

Answers


  1. I don’t know. but I know how to set connection-timeout

    If you use springboot default datasource you can try this config in your application.yml

    spring:
      datasource:
        hikari:
          connection-timeout: 1000
    
    Login or Signup to reply.
  2. You can set a global property, but can also specify that per session or query: Query

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search