javax.transaction.usertransaction 只能用于Session bean 和 BMP.是不用管,可是总不能a表插入成功,b表还空着呀!所以我也很糊涂,因该又设置的地方吧!

解决方案 »

  1.   

    将你的两个create封装在一个事务里面,
    两个entitybean的事务属性配置为required
    然后再异常处理里面回滚

    要是是sessionbean调用的话,将session调用的方法配置为required
    它里面的entity会作为事务的一部分的
    1.X里面很多事务属性
    2.0里面好像没几个可选的
      

  2.   

    将你的jsp文件作为一个webcomponent client发布好像可以配置
    事务属性的,记不得清楚了:(
      

  3.   

    to  ggyy:
      可以具体点嘛?我就是不知道如何 “
    将你的两个create封装在一个事务里面 ” 做啊!
    我目前是在Session bean中测试。
      

  4.   

    自管理session;
     在sessionbean的里面使用javax.transaction.usertransaction 
     得到该用户事务ur
     try
    {
    ur.begin();
     aHome.create(...);
     throw new Exception("Test");  // 发生异常时,如何rollback呢?
     bHome.create(...);
    ur.commit();
    `}catch(...)
    {
     rollback;}
    可不可以?
      

  5.   

    在EJB文件中:protected SessionContext context;try {
      con = getConnection();
      .....
    } catch(Exception e) {
      context.setRollbackOnly(); 
      throw e;
    } finally {
      closeCon(con);
    }百试百爽!
      

  6.   

    The exceptions thrown by enterprise beans fall into two categories: system and application. A system exception indicates a problem with the services that support an application. Examples of these problems include the following: a database connection cannot be obtained, a SQL insert fails because the database is full, or a lookup method cannot find the desired object. If your enterprise bean encounters a system-level problem, it should throw a javax.ejb.EJBException. The container will wrap the EJBException in a RemoteException, which it passes back to the client. Because the EJBException is a subclass of the RuntimeException, you do not have to specify it in the throws clause of the method declaration. If a system exception is thrown, the EJB container might destroy the bean instance. Therefore, a system exception cannot be handled by the bean's client program; it requires intervention by a system administrator. An application exception signals an error in the business logic of an enterprise bean. There are two types of application exceptions: customized and predefined. A customized exception is one that you've coded yourself, such as the InsufficentBalanceException thrown by the debit business method of the SavingsAccountEJB example. The javax.ejb package includes several predefined exceptions that are designed to handle common problems. For example, an ejbCreate method should throw a CreateException to indicate an invalid input parameter. When an enterprise bean throws an application exception, the container does not wrap it in another exception. The client should be able to handle any application exception it receives. If a system exception occurs within a transaction, the EJB container rolls back the transaction. However, if an application exception is thrown within a transaction, the container does not roll back the transaction. 
      

  7.   

    不过我觉你那样的logic本身就允许前一个表插入
    。。
    application的错误container不会回滚事务的
      

  8.   

    to ggyy:
      可以给我你的qq嘛?