Search code examples
javaspringexceptiondao

Spring DAO Repository exception handling


In Spring Docs there's a statement that @Repository annotation enables an "exception translation" but no additional details available.

What is this feature about and how it works?


Solution

  • Anything the DAO throws will be unchecked. Don't catch anything in the DAO. If you catch exceptions in the DAO or within the service method, Spring won't know to rollback the transaction. Configure exception-handling at the controller layer (using an exception handler, not with try-catch), that is where the data access exceptions will usually be caught, because there is nothing to do to handle them except to log them.