Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeout Exception with Spring Data Jpa

Which specific exception could i catch in case Spring Data Jpa repository query gets timeout ?

Lets say that i have repository like this one:

public interface VoucherRepository extends CrudRepository<VoucherEntity, String> {

    @Transactional(readOnly = true, timeout = 30)
    VoucherEntity findByCode(String code);

    List<VoucherEntity> findAllByCodeIn(List<String> codes);
}

Which exception would be seen by caller when timeout happens ?

I don't know how to simulate this scenario, bonus question would be how to do that?

Used database is PostrgreSQL.

like image 329
John Avatar asked May 29 '26 18:05

John


1 Answers

The exception you would get is QueryTimeoutException which is a subclass of the DataAccessException, which is the generic "something went wrong while using Spring to access a DB".

like image 132
Gergely Bacso Avatar answered Jun 01 '26 07:06

Gergely Bacso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!