4 Replies Latest reply on Feb 17, 2008 2:58 PM by pmuir

    Validation patter -> Invalid State

    enda

      Hey, I have a question about annotation @Pattern and seam validation of the annotated field. I have this annotation

       @NotNull
       @Pattern(regex="[a-zA-Z]?[a-zA-Z0-9]+",
       message="Username must start with a letter, and only contain letters or numbers")
       public String getFirstName() {
       return firstName;
       }
      


      When I call this from view form I will get:
      /*message*/
      Exception was thrown:validation failed for: edu.baylor.icpc.model.businessobjects.PersonInfo


      and log:



      01:19:02,534 ERROR [ExceptionHandler] Exception[Ljava.lang.StackTraceElement;@875e63
      01:19:02,534 ERROR [ExceptionHandler] Exception
      org.hibernate.validator.InvalidStateException: validation failed for: edu.xx.xx.model.businessobjects.PersonInfo
       at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:143)
       at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:172)
       at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
       at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
      
       ...
      
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
       at java.lang.Thread.run(Thread.java:619)
      01:19:02,537 WARN [ReadWriteCache] An item was expired by the cache while it was locked (increase your cache timeout): edu.xx.xx.model.businessobjects.PersonInfo#2
      
      


      Next valid attempt also fail:

      /*message*/
      Exception was thrown:null
      Transaction failed


      [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [edu.xx.xx.model.businessobjects.PersonInfo#2]
      ...
      Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [edu.baylor.icpc.model.businessobjects.PersonInfo#2]
      
      


      I guess that here I am supposed to call entityManager.merge() to get valid object state?
      But what about @Pattern validation. Is that expected behavior?

      (When I use entityHome from seam-gened application it fails too)

      Thanks Tomas

        • 1. Re: Validation patter -> Invalid State
          enda

          nope entityManager.merge() did not work. So it seems that @Pattern validation is ignored in JSF live cycle and applied at backend logic? I was expecting that seem handles this? Or what could be wrong?

          • 2. Re: Validation patter -> Invalid State
            enda

            I think I got it.

            if I will use

            <s:validateAll>
             <h:inputText ...
             <f:validateLength minimum="0" maximum="100" />
             </h:inputText>
            </s:validateAll>
            


            It will break hibernate validation. You can assume that f:validateLength does not need to be there, but what other validators, are they valid with hibernate validation?

            Tomas

            • 3. Re: Validation patter -> Invalid State
              enda

              I also read and can confirm the think that empty field that has pattern annotation and is not required will cause an exception when new object is created. Can I somehow avoid to it? I assume that value "" cannot be evaluated?

              • 4. Re: Validation patter -> Invalid State
                pmuir

                Yes s:validateAll only adds the hibernate validator if there is no other validator specified. Also nest s:validate and it will work.