Spring CrudRepository exceptions

Spring has built-in exception translation mechanism, so that all exceptions thrown by the JPA persistence providers are converted into Spring's DataAccessException - for all beans annotated with @Repository (or configured).

There are four main groups -

  • NonTransientDataAccessException - these are the exceptions where a retry of the same operation would fail unless the cause of the Exception is corrected. So if you pass non existing id for example, it will fail unless the id exists in the database.

  • RecoverableDataAccessException - these are the "opposite" of the previous one - exceptions which are recoverable - after some recovery steps. More details in the API docs

  • ScriptException - SQL related exceptions, when trying to process not well-formed script for example.

  • TransientDataAccessException - these are the exception when recovery is possible without any explicit step, e.g. when there is a timeout to the database, you are retrying after few seconds.

That said, the ideal place to find documentation about all exceptions - is in the API itself - just go through the hierarchy of DataAccessException.