'TransactionSynchronizationRegistry removes resource after bean call end

I have two EJB applications deployed on a WebLogic 11g, each with a single EJB. The EJB from the first one look up the EJB in the second one (using JNDI) and calls a method. Now, I want to bind some resources to the "JTA transaction context" so that I can access them from a static context in both EJBs. For this purpose, I use the TransactionSynchronizationRegistry interface.

However, if I bind a resource to a key in an EJB deployed with the first application, call the EJB deployed with the second application, and within that EJB I bind a resource to the same key, once the second application EJB is done, the first application EJB sees a null value bound to that key. Is there a way to keep the resource bound to that key after the second application EJB is done? Should I try to solve this another way?

To make it a bit clearer, this is what happens:

  1. app1-ejb (EJB from the first application) binds a resource to a key "some-key"
  2. app1-ejb looks up app2-ejb and calls a method
  3. app2-ejb binds a resource to the key "some-key", overriding the initial value
  4. app2-ejb is done and returns
  5. app1-ejb continues, but when it tries to get the resource bound to "some-key" it gets null

Keep in mind that if I omit step 3), in step 5) the resource stays bounded!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source