Reputation: 173
I have a spring-boot application which has a POST REST API which intern inserts data to Postgresql using JPA and Hikari. Since the Post requests huge in numbers, I am planning to implement Spring Retry on JPA built-in methods like save(),saveAll(),findAll() etc.,
My question is that is it good idea to do retry when there is time-out/connection failure from database ? (or) spring-boot or JPA already does this? if so please share the reference which mentions this.
Upvotes: 0
Views: 1340
Reputation: 9102
The responsibility of giving you a healthy connection is that of the connection pool which constantly monitors the available connections. Before handing over a connection to you HikariCP tests the connection using either a test query or API ( in case the jdbc driver is JDBC4 compliant). More info here and here.
However once a connection is handed over and if there is a network issue while executing the query , the client would get an Execption. Is retry then a good idea ? I think for read queries this should be fine but for queries which changes data may not be good. For e.g, your insert is successful but before the client gets the acknowledgement of transaction commit, a network issue occurs. So now the data is inserted. If you try again you will end up inserting twice.
Upvotes: 1