1
  1. I've an EJB method methodA() which is annotated with TransactionAttribute.REQUIRES_NEW.
  2. methodA() calls two EJB methods (lets say methodB(), methodC())running on a remote server (IIOP communication)
  3. methodB() performs few database inserts.. methodB is also annotated with TransactionAttribute.REQUIRED
  4. methodC() which is is also annotated with TransactionAttribute.REQUIRED and I'm making it throw some runtime exception to test transaction management.
  5. When I test my methodA for transaction management, I noticed the following ..

In OpenEJB log,

  1. TX Requires_New: No transaction to suspend.

  2. TX Requires_New : Started Transactions ... gerenimo TransactionImpl....

  3. logs from methodB execution... completes.

  4. methodC throws some RuntimeException

  5. TX Requires_New : Rolling Back transaction...

============

Even though it says Transaction is being rolled back.. the database records saved through methodA() still appears in the database. I want the database inserts should be rolled back as well.

Can you please help me understand what might be going wrong?

4

1 回答 1

0

问题是方法 A、B 和 C 在不同的事务上下文中运行,因此,在您的进程中,有三个不同且独立的事务在隔离中执行。

每个应用服务器定义一个事务上下文,它由部署在同一服务器中的 EJB 共享。

当您调用在远程服务器中运行的 EJB 时,不会使用当前事务。

如果要在不同的远程服务器上共享相同的事务,则必须实现分布式事务。

于 2013-06-23T02:21:09.773 回答