2 Replies Latest reply on Dec 23, 2006 5:45 PM by Amit Kasher

    inconsistent exception handling in hibernate validation

    Amit Kasher Newbie

      I am using hibernate validation for JPA entities and ejb3 stateless session beans.

      When the entity has a generated value id, the InvalidStateException is itself thrown to the ejb client (a servlet in my case). However, when the entity's id isn't annotated with @GeneratedValue, the InvalidStateException is thrown in a PersistenceException which is in a JBossRollbackException which is in a RuntimeException.

      Does anyone know the reason for that or if there is anything I can do to make it always throw the InvalidStateException directly and not wrap it in 2 other exceptions?

      (I'm using MySQL)

      Thanks.

        • 1. Re: inconsistent exception handling in hibernate validation
          Amit Kasher Newbie

          I forgot to mention that JBoss doesn't wrap the InvalidStateException in EJBException because I marked this exception as an application exception, and as one that requires rollback in ejb-jar.xml the following way:

          <application-exception>
           <exception-class>org.hibernate.validator.InvalidStateException</exception-class>
           <rollback>true</rollback>
          </application-exception>
          


          • 2. Re: inconsistent exception handling in hibernate validation
            Amit Kasher Newbie

            I just saw that when it is not an entity creation but rather it is an update on an existing entity, I'm consistently getting the InvalidStateException inside a PersistenceException which is inside a JBossRollba... which is inside a RuntimeException.

            This is very inconvenient. Is it possible to force the InvalidStateException to be thrown unwrapped from within the EJB? (aside from the EJBException wrap which can be avoided by the specification defined <application-exception> mark on InvalidStateException, as shown in my previous post).

            Thanks