2 Replies Latest reply on Oct 24, 2008 11:53 AM by benitojuarez

    Transaction closed after constraints violation

    benitojuarez

      Hello,


      after persisting an entity bean i got following error:


      Duplicate entry 'Hokkaido-houses-2890' for key 2


      It's ok, because i violated a constraint in the mysql database. The problem is, that the hibernate connection seems to be closed. The next flush-statement causes the following error:


      '17:24:01,562 ERROR JDBCExceptionReporter Transaction is not active: tx TransactionImple < ac, BasicAction: a964180:750:4900340b:1e70 status: ActionStatus.ABORT_ONLY >; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: a964180:750:4900340b:1e70 status: ActionStatus.ABORT_ONLY >)
      17:24:01,562 ERROR STDERR org.hibernate.exception.GenericJDBCException: Cannot open connection
      '


      thx for help
      BJ

        • 1. Re: Transaction closed after constraints violation
          fernando_jmt

          That's the expected behaviour. If some exception is thrown by the database, the transaction must rollback.
          What I generally do to deal with this is to mark the involved methods with     @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW).

          • 2. Re: Transaction closed after constraints violation
            benitojuarez
            don't work

            i encapsulated the creating of a single bean in a method annotated @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW). The call of this method is done in a loop and surrounded with try-catch.
            At first the entities are stored, but after the constraint violating entity all following entities are not stored in database! No exception is thrown.
            If i write entityManager.flush() in the called method, this causes an exception: no transaction is in progress

            BJ