Hi,
We have updated the GenericHibernateDAO findById method to catch ObjectNotFoundException and re-throw some custome exception:
Code:
public T findById(ID id, boolean lock) throws DataAccessException {
T entity;
try {
if (lock)
entity = (T) getSession().load(getPersistentClass(), id, LockMode.UPGRADE);
else
entity = (T) getSession().load(getPersistentClass(), id);
} catch (ObjectNotFoundException ex) {
log.debug("Could not find object by " + id);
throw new DataAccessException(DataAccessError.NOT_FOUND);
}
return entity;
}
It does not catch the excetion! We replaced it with java.lang.Throwable nothing happens and the catch does not catch any thing. Should we catch the exception some where else?
The signature of Session.load method shows that it throws HibernateException. The inersting thing is that when we remove the try/catch block the compiler does not show any complie errors and does NOT complain about uncoughted exceptions!
Seems to be tricky to us, any comments!
Regards,
Alireza Fattahi