4 Replies Latest reply on Aug 22, 2008 4:53 PM by Rahul Phadnis

    EJB3 transaction propagation

    Rahul Phadnis Newbie

      Hello,
      I need help with transactions in EJB3.

      I have an EJB which is called at a regular frequency using a timer. The EJB has a method with the @Timeout annotation. The method also specifies the REQUIRES_NEW transaction attribute. In this method, I am retrieving a list of records from the database. For each record, I am calling another method (update) in the same bean to update that record. The update method also specifies REQUIRES_NEW transaction attribute.

      What I want to know is, if the updating of all the records takes more time than the transaction time out specified in the jboss configuration, will the update of all records be rolled back ?

      What seems to be happening is the list is long and it takes more than 300 seconds to do the update of all records. Once that happens none of the records get updated. But I thought by adding the TransactionAttributeType.REQUIRES_NEW attribute on the update method,

      I am trying to specify that each record should be updated in a separate transaction.

      Here is some pseudo code:

      @Timeout
      @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
       public void updateList(Timer timer) {
       List<Record> list = getRecords();
       for (Record r : list) {
       update(r);
       }
       logger.log("done");
      }
      
      @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
      private void update(Record r) {
       //call another webservice to get update data
       // set updated fields in record
       //call merge on the injected RecordDA
       recordDA.merge(r);
      }
      
      


      Please help.

      Rahul Phadnis