I’m currently working on a project that uses data access on different databases. Our main database is accessed through Hibernate (either via the Criteria framework, or HQL queries), but we also have accesses to other dbs using plain JDBC / SQL queries (via Spring-Jdbc).
For some of our JDBC calls, we had to deal with the possibility of the DAO layer throwing some flavours of the Spring runtime TransientDataAccessException, like DeadlockLoserDataAccessException, or CannotAcquireLockException.
My question: should we plan for similar exceptions thrown by the Hibernate DAOs? It’s very difficult to write tests that would exhibit such exceptions, and I don’t want to build support for these if they cannot be thrown. And if they can, which exceptions exactly? What do you think?
Exceptions thrown from your Spring backed persistence implementation are not really rooted in Spring => they are data access exceptions.
Hence you can get similar exceptions from a pure Hibernate implementation e.g:
LockAcquisitionException: indicating a problem acquiring lock on the database
Having said that, testing for these exceptions specifically would not be wise. Hence they are
RuntimeExceptions. If you getting these exceptions from your Spring backed implementation, I would rather focus on solving the problem.