0 Replies Latest reply on Jul 15, 2003 5:00 AM by cocobase

    a problem about CMP remove()'s transaction in JBoss

    cocobase Newbie

      reomoveUser() in my Session Bean
      it work's successful user.serName("user1") can be rollback
      but when i replace
      user.setName("user1") with
      user.remove()
      the transaction can't be rollback
      it do delete the data in DB why?
      public void removeUser(String userID, String classID) {
      try {
      Context ctx = new InitialContext();
      UserHome userHome = (UserHome) ctx.lookup("java:/comp/env/User");
      User user = userHome.findByPrimaryKey(Integer.valueOf(userID));
      user.setName("user1");
      ClassanduserHome cauHome = (ClassanduserHome) ctx.lookup(
      "java:/comp/env/Classanduser");
      cauHome.create(Integer.valueOf(userID), Integer.valueOf(classID));
      }
      catch (CreateException e) {
      sessionContext.setRollbackOnly();
      System.out.println(e.getMessage());
      }
      catch (FinderException e) {
      }
      }

      in my ejb-jar.xml
      <container-transaction>

      <ejb-name>User</ejb-name>
      <method-intf>Local</method-intf>
      <method-name>remove</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>User</ejb-name>
      <method-name>setName</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>Classanduser</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>Facade</ejb-name>
      <method-name>removeUser</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      <method-param>java.lang.String</method-param>
      </method-params>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>