jboss下面CMP的remove()的事务回滚失败,救命。。。

03-07-15 getdown
我在sessionBean里面方法

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");

//这里create出错事务回滚

cauHome.create(Integer.valueOf(userID), Integer.valueOf(classID));

}

catch (Exception e) {

sessionContext.setRollbackOnly();

System.out.println(e.getMessage());

}

}

有 cmp User 和 Classanduser

配置文件ejb-jar.xml

<container-transaction>

<method>

<ejb-name>User</ejb-name>

<method-intf>Local</method-intf>

<method-name>remove</method-name>

</method>

<trans-attribute>Required</trans-attribute>

</container-transaction>

<container-transaction>

<method>

<ejb-name>User</ejb-name>

<method-name>setName</method-name>

</method>

<trans-attribute>Required</trans-attribute>

</container-transaction>

<container-transaction>

<method>

<ejb-name>Classanduser</ejb-name>

<method-name>*</method-name>

</method>

<trans-attribute>Required</trans-attribute>

</container-transaction>

<container-transaction>

<method>

<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>

</method>

<trans-attribute>Required</trans-attribute>

</container-transaction>

这样可以顺利回滚

但是我把user.setName("user1");

改成user.remove();

不能回滚 即使后面create出错数据库里面的数据也因为user.remove()删除了

我的as是jboss3.2-tomcat4.1

猜你喜欢