Mar 30th, 2007, 11:13 AM
Translating Spring exceptions
Our application uses Spring and Hibernate for the core system. We have a simple 3 tier system: weblayer > service layer > dao layer.
We've setup the Spring transaction strategy with
and that is working fine (in conjunction with the @Transactional annotations). I've also tagged the Dao with the @Repository annotations.
The core is providing the API for a web front-end application. So what we want to do is translate all exceptions to our own API specific exceptions.
The problem is that we cannot catch those exceptions in our service layer (transactional layer), because some of the runtime exceptions (e.g. OptimisticLockingException) are thrown after the transaction is being committed.
Now are there several workarounds for this problem:
1) use a facade (non-transactional) / delegate layer
2) use AOP-around advice for exception translations: didn't get it to work properly
3) use another form of transactions (programmatic?)
What should I do to provide my own custom exceptions in proper way to the users of this API?