Announcement Announcement Module
Collapse
No announcement yet.
Catching Exceptions in classes wrapped with TransactionProxy Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Catching Exceptions in classes wrapped with TransactionProxy

    I'm experiencing a strange issue. I am calling a Spring-managed bean from a JSF managed-bean and for some reason, the JSF bean won't catch a checked exception. Here's the method that throws the exception:

    Code:
       public void saveUser(User user) throws UserExistsException {
           try {
               dao.saveUser(user);
           } catch (DataIntegrityViolationException e) {
               throw new UserExistsException("User '" + user.getUsername()  +
                                             "' already exists!");
           }
       }
    The above "saveUser" method is in a UserManager class, which is wrapped in a TransactionProxyFactoryBean.

    In my JSF Bean I have:

    Code:
           try {
               userManager.saveUser(user);
           } catch (UserExistsException ue) {
               log.warn(ue.getMessage());
    
               // for some reason - MyFaces doesn't seem to catch this  exception
           } catch (DataIntegrityViolationException e) {
               log.warn(e.getMessage());
               addError("errors.existing.user",
                        new Object[] { user.getUsername(), user.getEmail()  });
    
               return "editProfile";
           }
    After some checking, it seems that the UserManager is unable to catch the DataIntegrityViolationException. I tried using + and - in my transaction attributes, but had no luck.

    Seems like I'm just not seeing something, as I'm guessing that catching exceptions should be possible in TransactionProxy-wrapped beans.

  • #2
    Any suggestions yet?

    I am also facing this issue, although slightly different. My service layer is wrapped by the TransactionProxyFactoryBean which then calls methods on a DAO setup by spring. In the DAO I am trying to catch an OptimisticLockingFailureException but I am unable to currently.

    I would like to be able to catch this exception in certain scenarios and rethrow it (as something non-spring specific) which is then picked up by my struts exception handler, so I can give a friendly message to the user explaining what happened. But I am unable to catch this in the DAO, and so the error propogates to my generic Exception Handler.

    Code:
    public void update(ReviewStatus reviewStatus) throws DataModifiedError {
    	try {
    		getHibernateTemplate().update(reviewStatus);
    	} catch (OptimisticLockingFailureException ex) {
    		logger.warn("Optimistic locking failed when updating review status");
    		throw new DataModifiedError(ex.getMessage(), ex);
    	}
    }
    This exception is never caught, even if you change the catch block to catch "Throwable" you cannot catch it. Any suggestions?

    Comment


    • #3
      Ah, I seem to have found something that seems to makes sense. According to this thread I guess this is a timing issue. A flush also seems to straighten this out for me.

      http://forum.springframework.org/sho...atch+exception
      Last edited by robyn; May 14th, 2006, 05:26 PM.

      Comment

      Working...
      X