一个事务就行了。 实现数据的完整性。
public a(){
  yourconnect.setAutoCommit(false);
   a1();
   a2();
   a3();
  yourconnect.setAutoCommit(true);
  yourconnect.commit();
  }

解决方案 »

  1.   

    感谢楼上几位的指导,谢谢!
    可是我还是有一个疑问,就是:
    我在a1(),a2(),a3()里都向数据库对象进行了commit()的操作,
    (我想这一步的作用是把操作过的数据向数据库里进行实际的提交吧!)
    那么,只是如果其中某一个出错了,向数据库中提交的那些数据也会恢复回来吗?ThanX!对了,还有一个想问一楼的老大,所谓的事务嵌套,
    是不是说如果我在a1,a2,a3里面已经有了事务处理的代码(处理他们各自的事务),
    在他们被调用的时候,也可以再次使用事务处理,来处理a1,a2,a3之间的关系呢?谢谢谢谢谢谢谢谢
      

  2.   

    还有更简单的,部署描述符里设置事务管理为容器管理(你上面那个是JTA事务处理),然后指定事务属性为Required,RequiresNew,Mandatory,NotSupported,Supports Never之一就行了,具体含义和使用范围请参考J2EE文档。
      

  3.   

    ejb-jar.xml里面加上:        <container-transaction>
                <method>
                    <ejb-name>SystemSetupSession</ejb-name>
                    <method-name>*</method-name>
                </method>
                <trans-attribute>Required</trans-attribute>
            </container-transaction>上面*代表SystemSetupSession下所有方法都要进行事务处理;
    Required是默认项,代表当一个客户程序请求它时,如果客户程序不在事务中,那么产生一个新的事务,如果在,就包含到了客户程序中的事务中去了。
      

  4.   

    to villagehead(村长) 
    确实如你所说 可以那么做关于用容器控制事务 我也觉得很不错
    一般对于一个Bean中的所有方法都设成Required 出错时自动Rollback
    如果设成Support 那么方法A本身不会Rollback 但是方法A中调用的方法B如果是Required那么这个方法B会Rollback
    如果设成Not Support 方法B就算是Required在方法A中被调用的话也不能RollBack了
    还有Requred new创建一个新的事务
    暂时就记得这么多
      

  5.   

    再想请教,如果我是一个事务处理讨一个事务处理的话,
    比如A调用B,那么这个A的事务处理应该怎么设置?
    还有B的事务处理又怎么设置呢?
    (B的事务处理是不是就是要和tianboguang(其实,我是一个程序员)说的那样呢?)to tianboguang(其实,我是一个程序员):
    我用你的方法,把B的ejb-jar.xml像你说的那样改了,
    但是在用ant编译的时候,出现了
    ejbc:     [java] Warning: In 'ejb-jar.xml', EJB 'AppendFunctionsEjbHome' has containe
    r-transactions set when the EJB has a transaction-type of 'Bean'. The container-
    transaction settings will be ignored.
    的错误。
        在启动weblogic的时候,也出现了
    Warning: In 'ejb-jar.xml', EJB 'AppendFunctionsEjbHome' has container-transactio
    ns set when the EJB has a transaction-type of 'Bean'. The container-transaction
    settings will be ignored.
    的错误提示!    是不是我的那个调用他的ejbbean的ejb-jar.xml有什么问题呢?
    需要怎么改呢?AppendFunctions是我那个被调用的ejbbean,其中有事务处理的内容!
      

  6.   

    那是警告,不是错误,The container-transaction settings will be ignored.
    是说你设置的容器事务将被不理睬,因为你的客户程序已经在一个事务中了,你设置的“Required”代表当一个客户程序请求它时,如果客户程序不在事务中,那么产生一个新的事务,如果在,就包含到了客户程序中的事务中去了。
    以下是J2EE指南里的描述:
    Required 
    If the client is running within a transaction and invokes the enterprise bean's method, the method executes within the client's transaction. If the client is not associated with a transaction, the container starts a new transaction before running the method. The Required attribute will work for most transactions. Therefore, you may want to use it as a default, at least in the early phases of development. Because transaction attributes are declarative, you can easily change them at a later time.