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.
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.