Announcement Announcement Module
Collapse
No announcement yet.
Can a caller be notified when there is a rollback in the called method? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can a caller be notified when there is a rollback in the called method?

    In my controller I would like to be able to return a message that indicates that an error produced a rollback.

    For example:
    Code:
        someService.insertRowInDB ( someDomainObject ) ; // this method annotated with  @Transactional
    
        if (thereWasARollback) {
              return rollback ; // view name
        } else {
              return success ; // view name
        }
    I know I could detect the exception that triggers a rollback and set a return value that can be used to determine if there was a rollback. I would rather have Spring tell me.

    Thanks,
    bils

  • #2
    Catch the exception from the service... Do something in the catch...

    Code:
    try {
      someService.insertRowInDB ( someDomainObject );
      return success;
    } catch (DataAccessException dae) {
      return rollback;
    }
    You now also have the means to detect what went wrong and give some informative message to the user.

    Comment

    Working...
    X