Overriding timeout for database connection in properties file

谁说我不能喝 提交于 2019-12-08 03:41:27

Assuming that you're using Spring Boot you can try:

spring.transaction.defaultTimeout=1

This property sets defaultTimeout for transactions to 1 second.

(Looking at the source code of TransactionDefinition it seems that it is not possible to use anything more precise than seconds.)

See also: TransactionProperties


javax.persistence.query.timeout

This is a hint for Query. It is supposed to work if you use it like this:

entityManager.createQuery("select e from SampleEntity e")
    .setHint(QueryHints.SPEC_HINT_TIMEOUT, 1)
    .getResultList();

See also QueryHints


spring.jdbc.template.query-timeout

Remember that according to the JdbcTemplate#setQueryTimeout javadoc:

Any timeout specified here will be overridden by the remaining transaction timeout when executing within a transaction that has a timeout specified at the transaction level.


hibernate.c3p0.timeout

I suspect that this property specifies timeout for getting from the connection pool, not for a query execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!