0 Replies Latest reply on Apr 12, 2007 9:14 AM by Mauro Ciccio

    Transactions on session facade in front of jBPM api

    Mauro Ciccio Newbie

      Hi i have a session facade "addUser" to add users and memberships to JBPM db using IdentitySession api.
      I want rollback transaction if some runtimexception occurs, but it doesn't work and data is persisted anyway.
      I'm using datasource on jboss3.2.3 and i've configured hibernate to use that data source for its connections.

      Maybe i'm missing somewhat, please help me.
      Below the code:

      public void addUser(HashMap params) {

      log.debug("Start addUser");

      IdentitySession identitySession = Util.getIdentitySession();

      User user = new User( (String)params.get("userName"));
      user.setEmail( (String)params.get("email"));
      user.setPassword((String)params.get("userPwd"));

      String[] userGroupIds= (String[])params.get("userGroups");

      if ( userGroupIds!=null) {

      long groupId=0;

      for (int i=0; i<userGroupIds.length;i++) {

      groupId = Long.parseLong( userGroupIds);

      addMembership(user,groupId,identitySession);
      }
      }

      identitySession.saveUser(user);
      identitySession.getSession().flush();


      log.debug("End addUser");
      }


      private void addMembership( User user, long groupId, IdentitySession identitySession) {
      Group group = identitySession.loadGroup(groupId);

      Membership membership = Membership.create(user,user.getName()+"_"+group.getId(), group);

      user.addMembership(membership);

      /*to simulate exception for testing*/
      if (true) {
      throw new RuntimeException("Error membership add");
      }

      }