0

I am using spring data jpa in our application. I want to throw timeout exception, if database does not respond. How can we set timeout in simple jpa queries, without using entity manager ?

Regards, Stephan

Stephan
  • 91
  • 1
  • 1
  • 6
  • Does this answer your question? [How to set the timeout period on a JPA EntityManager query](https://stackoverflow.com/questions/24244621/how-to-set-the-timeout-period-on-a-jpa-entitymanager-query) – Jens Schauder Jan 14 '21 at 12:38
  • Hallo, thanks for your reply. I am not using entity manager. I am using simple JPA queries. In addition, am using spring boot with spring cloud connectors. Therefore, i tried with following: spring.jpa.properties.javax.persistence.query.timeout: 0 spring.datasource.hikari.connection-Timeout: 0 , but it did not help. – Stephan Jan 19 '21 at 17:35

1 Answers1

0

Did you try spring.jpa.properties.javax.persistence.query.timeout=60000 in application.properties ?

If your problem still exists try to add Spring Transaction annotation like the below code.

@Transactional(timeout=10)
@Override
public List<EntityModel> function(EntityModel model) {

}
Faramarz Afzali
  • 726
  • 1
  • 10
  • 24