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?

1 Answers1

0

The problem is that methodA, B and C are running in different Transactional Contexts, therefore, there are three different and independents transactions executing in isolation within your process.

Each appserver defines a transactional context which it's shared by the EJBs deployed in the same server.

When you make a call to an EJB running in a remote server, the current transaction is not used.

You have to implement a distributed transaction if you want to share the same transaction over different remote servers.

Gabriel Aramburu
  • 2,951
  • 2
  • 16
  • 20
  • methodB and methodC are on the same server and they are third party EJBs.. Documentations says, if we provide a transaction that will be used while executing B and C. Now how do I ensure a distributed transaction is implemented from my EJB methodA? – Himadri Pal Jun 23 '13 at 03:58
  • Ok, but even with methodB() and methodC() running in the same server the situation is the same due to methodA() is the caller. It would be different if methodB() calls methodC(), in this case to throw a runtime exeption in C will rollback the data inserted in B due to they are running in the same transactional context. To be honest, distributed transaction is a big topic, maybe [this](http://stackoverflow.com/questions/4217270/what-is-a-distributed-transaction) can be a good starting point. Also, try to find examples according to your appserver and EJB's version. – Gabriel Aramburu Jun 23 '13 at 14:36
  • thanks Gabriel,I did some reading and realized, may be my side of EJBs running on OPenEJB/Websphere I do not have to do anything as its already Contrainer Managed and there is no datasource defined on my EJB (i.e methodA). Do you know how do I make sure whether remote EJBs(methodB and methodC) support distributed transaction? – Himadri Pal Jun 23 '13 at 16:03