2

Acording to another post [1] there's no difference between invoking a session EJB via JNDI lookup and using the @EJB annotation. However, in the following scenario:

1.- call session EJB1(JDBC inserts here) 2.- From EJB1, call session EJB2 (more inserts here) 3.- Rollback the transaction (from EJB1)

If I use the @EJB annotation it works fine, but with the JNDI lookup it doesn´t, the transaction in the second EJB is a new one and the rollback doesn´t happen. All this with CMT.

I'm deploying all this stuff in a Geronimo/ibmwasce-2.1.1.6.

¿Do I need to pass the transaction from one EJB to another explicitly? I thought it was the continer job. ¿Any clues?

[1] @EJB annotation vs JNDI lookup

Update:

Code via annotation:

@EJB
private CodAppEjb codAppejbAnotacion; 

Code via jndi:

CodAppEjb codAppejb;
InitialContext ctx;
Properties properties= new Properties();
properties.setProperty("java.naming.provider.url", "ejbd://127.0.0.1:4201");
properties.setProperty("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
ctx = new InitialContext(properties);
codAppejb= (CodAppEjb) ctx.lookup("CodAppEjbBeanRemote");

The transaction code is just the same.

Community
  • 1
  • 1
Aitor
  • 43
  • 7
  • Transaction behavior should not vary based on lookup vs injection. I recommend including the code snippets that work and don't work. I must also point out that stateful session beans are an example where injection and JNDI vary, since JNDI must be used as the "factory". – Brett Kail Sep 07 '13 at 05:40
  • Ok, I've updated the post with the code snippets, thank you bkail. – Aitor Sep 09 '13 at 07:26

1 Answers1

3

It seems, you have a transaction propagation problem.

The problem seems to be, that in your JNDI lookup you search for the remote EJB (not Local), which does NOT get executed in the same transaction context as EJB1.

When using the @EJB annotation above, the local implementation is injected, with the same transaction context.

V G
  • 18,822
  • 6
  • 51
  • 89
  • This post confirms this behavior: http://blog.pwsindonesia.com/index.php/2011/06/07/how_to_call_geronimo_2_2_local_ejb_using – ewernli Sep 09 '13 at 08:21