日期:2014-05-18 浏览次数:20830 次
@Stateless
@Remote
@TransactionManagement(TransactionManagementType.CONTAINER)
public class RoleBeanImpl implements IRoleBean {
@Resource
private SessionContext context;
@Resource(mappedName = "common_EaoBean/remote")
private ICommonEao commonEao;
@Resource(mappedName = "public_QueryBean/remote")
private IPublicQuery publicQueryEao;
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void addRole1(Role role) {
System.out.println("----------------RoleBeanImpl.addRole------------");
commonEao.save(role);
throw new EJBException(); //这里抛异常,上句应该回滚,实际没有回滚
}
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void addRole2(Role role) {
try {
commonEao.save(role); //向数据库中插入一条记录,如果后面报异常,这句应该回滚,但实际没有回滚
Role role1 = new Role();//新建一个空的role
commonEao.save(role1);//这句抛异常,但是前面插入的role不回滚,插入成功
System.out.println("----------------RoleBeanImpl.modifyRole------------");
} catch (Exception e) {
e.printStackTrace();
context.setRollbackOnly();
}
}