I use Hibernate as the persistence mechanism. Let's say I have a transaction that is dependent upon another persistent object which is loaded during that transaction. In the "load" method for the child object we use something like this:
Since the ObjectRetrievalFailureException is a runtime exception, Spring automagically rolls back the transaction. I realize I could just return null from the getUser method or return a checked exception.. but what if I don't want to for whatever reasons. Is there any way for me to downgrade the RuntimeException to a checked Exception so that I can declaratively determine whether or not to rollback?Code:public User getUser(String username) { User user = (User) getHibernateTemplate().get(User.class, username); if (user == null) { throw new ObjectRetrievalFailureException(User.class, username); } return user; }
-Matt


Reply With Quote