Just as a follow-up I was able to get this working using AOP and after throws advice. One nice aspect is that now I do not need to worry about try...catch blocks in my service layer methods, the interceptor handles translating them into the correct checked exceptions. OTOH, it feels a little wrong to have that so detached from the code, but I suspect that is just my discomfort with a new technology (AOP).
The new service layer code looks like the following:
Code:
@Transactional
public void saveItem(final Item item) throws MyAppException
{
itemDao.saveOrUpdate(item);
}
Then the interceptor looks like:
Code:
@AfterThrowing(pointcut = POINTCUT_EXPRESSION, throwing = "oolfe")
public void handleException(final ObjectOptimisticLockingFailureException oolfe)
throws MyAppException
{
throw new StaleObjectMyAppException(oolfe);
}
@AfterThrowing(pointcut = POINTCUT_EXPRESSION, throwing = "dae")
public void handleException(final DataAccessException dae)
throws MyAppException
{
throw new MyAppException(dae);
}