1 Reply Latest reply on Sep 4, 2008 9:58 PM by torakuma

    Help with @AssertTrue and OptimisticLockException

    torakuma

      Hi-


      I'm trying to do some complex validation on my entity bean using @AssertTrue and having trouble getting it to play nice with a seam conversation.


      My entity bean:



          @AssertTrue(message = "#{messages.someErrorMsg}")
          public boolean hasSomeGoodFields() {
              return checkFields();
          }



      My EntityHome class:



          @Override
           public String update() {
              try {
                  return super.update();
              } catch (InvalidStateException ise) {
                  facesMessages.add(ise.getInvalidValues());
              }
              return null;
          }



      When I edit my bean with 'bad' fields, it looks great and I see the error I expect in the web page.  When I subsequently fix the 'bad' fields and submit, I get a:


      javax.persistence.OptimisticLockException



      I suspect this has something to do with a rollback happening and then seam thinking this is a different edit (hence the optimistic lock issue).


      Can anyone give some advice on how to get @AssertTrue errors working with a conversation?


      Thanks in advance for your help!


      D

        • 1. Re: Help with @AssertTrue and OptimisticLockException
          torakuma

          I finally got it working after reading the post Problem with Validator


          Dan Allen provides a great example in there on how to use an Interceptor with an annotated method for validation.  All I had to do was switch the InterceptorType.CLIENT to InterceptorType.SERVER and it worked as-is.


          Now my update method looks like this:



              @Override
              @ValidatableAction
              public String update() {
                  return super.update();
              }



          ... and the validators are called manually from the HomeInterceptor.  Now I can slap the @ValidatableAction on my action methods wherever I need them.  Very cool.



          D