3 Replies Latest reply on Oct 23, 2008 6:32 AM by adamw

    Hibernate validator and roll back errors

    talios

      Hey all,

      Has anyone had any issues with envers and Hibernate Validator? Esp. when the validator throws an InvalidStateException for validation errors?

      I'm noticing envers doing some weird shiz under this condition which is causing some real weird headaches for our app.

      The first exception I see (hibernate validator) is:

      org.hibernate.validator.InvalidStateException: validation failed for: smx3.schema3.TelecomNumber
       at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:148)
       at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:172)
       at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:160)
      


      which is immediately followed up with the following envers based exception (I'm blaming envers based on its appearance in the trace):

      23.10.2008 16:35:24.018 *WARN* [btpool0-13] org.hibernate.util.JDBCExceptionReporter SQL Error: 0, SQLState: 23505
      23.10.2008 16:35:24.018 *ERROR* [btpool0-13] org.hibernate.util.JDBCExceptionReporter ERROR: duplicate key violates unique constraint "pk_party"
      23.10.2008 16:35:24.019 *ERROR* [btpool0-13] org.hibernate.event.def.AbstractFlushingEventListener Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: could not insert: [smx3.schema3.Party]
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2272)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2665)
       at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:60)
       at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
       at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
       at org.jboss.envers.synchronization.VersionsSync.beforeCompletion(VersionsSync.java:138)
       at com.atomikos.icatch.jta.Sync2Sync.beforeCompletion(Sync2Sync.java:73)
       at com.atomikos.icatch.imp.TransactionStateHandler.commit(TransactionStateHandler.java:253)
       at com.atomikos.icatch.imp.CompositeTransactionImp.doCommit(CompositeTransactionImp.java:509)
       at com.atomikos.icatch.imp.CompositeTerminatorImp.commit(CompositeTerminatorImp.java:138)
      


      Beyond thinking envers shouldn't even be triggered under this circumstance (Hibernate shouldn't be getting passed org.hibernate.action.EntityInsertAction#preInsert to trigger the postInsert listeners - so why is envers waking up?) I'm intrigued by this looking like Hibernate wanting to insert my smx3.schema3.Party entity rather Party_versions.

      I wonder if this was a known issue thats resolve in the 1.x series (we're still running a 0.9 build due to other issues mentioned elsewhere in the forum).

      Cheers,
      Mark


        • 1. Re: Hibernate validator and roll back errors
          adamw

          Hello,

          I just tried validating a "@NotEmpty" constraint, and didn't get anything except the usual validation exception. What is your constraint, do you update just one entity or more?

          --
          Adam

          • 2. Re: Hibernate validator and roll back errors
            talios

            I'm persisting a new object that's 2-3 objects deep, and the validation in question thats being failed is:

             @Basic
             @Column(table = "telecom_number", name = "contact_number", nullable = true, insertable = true, updatable = true, length = 60)
             @Pattern(message = "{telecomNumber.invalid}", regex = "^\\+?[-0-9()\\s]{4,}(x[0-9]+)?$")
             public String getContactNumber() {
             return contactNumber;
             }
            


            I don't think the difference in validation method should matter thou.

            • 3. Re: Hibernate validator and roll back errors
              adamw

              I tried persisting a new entity, which has a relation (with cascade type all) to another entity, which has a field validated with @Pattern - and all worked well. Maybe when we solve the first issue you'll be able to update to 1.1 and then we'll see if the problem with validators is still there :)

              --
              Adam