这是测试代码 ,用的是jboss6 服务器,现在想测试的是jta 事务, 理想状态下,这里应该回滚,也就是说数据库中不应该能插入进数据,但是却插入了,我在看一个教程 它的代码进行后,服务器端确实回滚了,难道与jboss 版本有关,他用的是jboss4 就是想从远程使用jta 进行事务控制
@Test
public void testJta() throws Exception {
InitialContext ctx2 = new InitialContext();
StuManager ejb2 = (StuManager) ctx2.lookup("StudentEjb/remote");
UserTransaction tx2 = (UserTransaction) ctx2.lookup("UserTransaction");
try {
tx2.begin();
for (int i = 0; i < 10; i++) {
Student s = new Student();
s.setAge(11);
s.setName("s" + i);
ejb2.addStu(s);
}
tx2.rollback(); } catch (Exception e) {
tx2.rollback();
e.printStackTrace();
} }package org.jixiuf.session;import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;import org.jixiuf.entity.Student;@Stateless
public class StudentEjb implements StuManager {
 
@PersistenceContext(unitName = "ejb_19_jpa_m2o")
private EntityManager manager;

public void addStu(Student stu) {
manager.persist(stu);
 
}
}
package org.jixiuf.session;import javax.ejb.Remote;import org.jixiuf.entity.Student;@Remote
public interface StuManager {
public void addStu(Student stu);
 
}
 <?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0"> <persistence-unit name="ejb_19_jpa_m2o"
transaction-type="JTA">
<jta-data-source>java:/MySqlDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit></persistence>