Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decrease timeout for a my sql query in SpringBoot

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?

like image 775
Ankur Garg Avatar asked Feb 23 '15 15:02

Ankur Garg


1 Answers

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
like image 125
Andy Wilkinson Avatar answered Oct 22 '22 20:10

Andy Wilkinson