Spring CrudRepository exceptions

后端 未结 1 1984
太阳男子
太阳男子 2020-12-12 19:13

I have this Spring Data CrudRepository which handles the CRUD operations on a DB.

@Repository
public interface IUserRepository extends CrudRepo         


        
相关标签:
1条回答
  • 2020-12-12 19:34

    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.

    0 讨论(0)
提交回复
热议问题