I tried the following example: A SLSB, with a injected transaction scoped EntityManager, calls an injected SFSB, with an extended EntityManager. I tried the example on JBoss 4.2.3. Both the books I'm reading (Oreilly and Apress), tell that an exception should be thrown in this case (which is logical to me). But it seems from the previous example that an exception is NOT thrown; the transaction is propagated (I'm using @TransactionAttribute.MANDATORY in SFSB), but not the persistence context.
On the server:
I have a client that calls the SLSB from a "main" method:
Can someone explain please what I did wrong? Thanks
This is a nice example. It's true that an exception should be raised as the requirements are :
188.8.131.52 Requirements for Persistence Context Propagation If a component is called and the JTA transaction is propagated into that component: If the component is a stateful session bean to which an extended persistence context has been bound and there is a different persistence context bound to the JTA transaction, an EJBException is thrown by the container.
This is what I got under Glassfish : "java.rmi.RemoteException: There is an active transactional persistence context for the same EntityManagerFactory as the current stateful session bean's extended persistence context.". So I guess that JBoss is not working as expected.
I tried to extend your example, by making another stateful bean, using an extended persistent scope for the EntityManager. I wanted to make sure that calling the new stateful bean from the first stateful bean would propagate the first bean's extended persistence context. It worked as expected.