I use spring with @Transactional
annotation, and I catch the exception and for some exception I will retry 3 times.
For posgresql, when got exception, you can't use same Connection to commit any more.You must rollback first.
For my case, I use the DatasourceUtils
to get current connection and call connection.rollback()
manually. And the call the method recruive to retry.