Handling exceptions in the Spring Data layer
With traditional JDBC-based applications, exception handling is based on java.sql.SQLException
, which is a checked exception. It forces the developer to write catch
and finally
blocks carefully for proper handling and to avoid resource leakages such as leaving a database connection open. Spring, with its smart exception hierarchy based on RuntimeException
, spares the developer from this nightmare. Having DataAccessException
as the root, Spring bundles a bit set of meaningful exceptions, translating the traditional JDBC exceptions. Spring also covers Hibernate, JPA, and JDO exceptions in a consistent manner.
Spring uses SQLErrorCodeExceptionTranslator
, which inherits SQLExceptionTranslator
for translating ...
Get Spring MVC: Designing Real-World Web Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.