Results 1 to 2 of 2

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

  1. #1

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •