Discussions

EJB design: how to call ejbcreate more than once in single trans

  1. Hi
    i have to create multiple record in a table in single transaction ( say 10 records).i am using session facade. i am looping in session bean and calling create method of entity bean ( 10 times) .my requirment is , if any of the record gives error, all 10 records should get rolled back.
    what transaction attribute should i use.

    Thanks in advance
    Faisal
  2. Your entity beans should have a transaction attribute of either Required or Mandatory. That way they are forced to use the transaction provided by the session facade and will roll back if the session facade transaction rolls back. The main thing is that you don't use RequiresNew, NotSupported or Never on your entity beans as these values will result in each ejb create being and isolated operation.
  3. I will suggest, whatever is ur transaction attribute, make sure that in case of any problem you are throwing EJBException. If that is happening all the work done within one transaction context will be rolled back.

    Regards
    Chetan