How to decrease timeout for a my sql query in SpringBoot

hibernate, spring-boot, spring-jdbc, yaml

Solution

You can configure the timeout using JPA's `javax.persistence.query.timeout` property. The value is the timeout period in milliseconds. It's an optional part of the JPA spec, but Hibernate supports it. You can configure it in Spring Boot by adding the following to `application.properties`:

spring.jpa.properties.javax.persistence.query.timeout=60000

Problem

I am building a web application which uses MSSQL in backend to fetch queries. I am using SpringBoot and Hibernate . Now , if the database is down , it takes over 2 minutes for my query to timeout and throw below exception org.hibernate.exception.JDBCConnectionException: Could not open connection How to decrease the timeout in my application so that my queries timeout earlier in case db is down?

Original source