2 Replies Latest reply on Jan 30, 2008 8:50 AM by breako

    Transaction recovery

    breako

      Hi,
      I am using SEAM Managed EntityManager with FushMode set to Manual for a JTA datasource.
      When I flush the EntityManager for some invalid update, I get a database exception.
      I catch this exception, the entity I am updating is still attached and I try to correct the invalid data and then try to reflush the update. However I can't persist the change even though this time it is valid. I get a javax.persistence.TransactionRequiredException: no transaction is in progress exception.
      I am wondering is there any way I can recover from transaction failure?
      My code is below.

      @Name("manager")
      @Scope(CONVERSATION)
      public void SeamPOJO {
       @In
       private EntityManager em;
      
       @End
       public String commit () {
       // Create entity
       Person person = new Person();
       // set invalid data
       person.setName("namethatistoolong");
       em.persist(person);
       try {
       em.flush();
       } catch (Exception e) {
       // data is invalid correct it
       person.setName("john");
       em.flush();
       }
       }
      


      ~any advice, comments appreciated. Thanks


        • 1. Re: Transaction recovery
          pmuir

          After an exception occurs in the persistence layer, the transaction is unusable. You need a new transaction at this point. You should pre validate your data probably.

          • 2. Re: Transaction recovery
            breako

             

            "pete.muir@jboss.org" wrote:
            After an exception occurs in the persistence layer, the transaction is unusable. You need a new transaction at this point. You should pre validate your data probably.

            I have some corner cases where I can't pre validate data. I would therefore need to start a new transaction. How do I that if I am using to this approach?