2 Replies Latest reply on Jun 24, 2008 5:36 PM by Jacob Orshalick

    how to rollback transactions without throwing exception on container?

    Troy Tarrrant Newbie

      Hi,


      I have a batch process that stores records in a database and it must be atomic, but I don't want to throw an exception, instead I just want to put a message on the screen.


      I've got the current code but it doesn't rollback the previous inserts. How can I make the transaction automic?


      |
      try {
        for (int index=0; index < maxRecords; index++) {
          Record = new Record();
          // set data for next record
          // ...
          if (failValidation(record)) throw Exception("Invalid record");
          entityManager,persist(record);
        }
      }
      catch (Exception ex)
        facesMessages.add("The upload did not succeed. No records stored");
        Transaction.instance().setRollbackOnly();
      }|





      Now what happens is all the records upto the failed validation record still get inserted in the db even though I mark the transaction for rollback?


      How do you get batch uploads to be automic?


      Thanks


      Troy