1 Reply Latest reply on Feb 29, 2004 4:32 AM by pilhuhn

    Container Managed Transaction Doesn't Rollback

    jmejia424

      I have a SessionBean and a method where I am removing a CMP. I don't know why it doesn't roll back. I have executed my code and the record is still getting deleted. Even when I print ejbContext.getRollbackOnly(); the result is true. Why won't it rollback the delete?

      Here is the method:

      /**
      * Method used to remove all data associated to an Employee
      * @ejb:interface-method view-type="both"
      * @ejb:transaction type="Required"
      **/
      public boolean removePersonnelContainer(PersonnelContainer personnelContainer) throws Exception{
      // Start the logging time for this method
      long startTime = cat.isInfoEnabled() ? System.currentTimeMillis() : 0;

      if (cat.isDebugEnabled())
      cat.debug("removePersonnelContainer - Remove the Personnel with an ID of " + personnelContainer.getEmployee().getRecordId());

      try {
      ejbContext.getUserTransaction();
      EmployeeData employeeData = personnelContainer.getEmployee();
      Employee employeeBean = (Employee) employeeHome.findByPrimaryKey(new EmployeePK(employeeData.getRecordId()));
      employeeBean.remove();
      ejbContext.setRollbackOnly();

      throw new Exception("Rolled back transaction");
      } catch (Exception e) {
      cat.error("removeClient " + personnelContainer.getEmployee().getRecordId(), e);
      cat.error("Unable to remove the personnel with the given personnel Primary Key.");
      return false;
      } finally {
      LoggingUtils.infoElapsedTime((Logger) cat, "removePersonnelContainer", startTime);
      System.out.println("=====================>Rollback? " + ejbContext.getRollbackOnly());
      }
      }