users@glassfish.java.net

passing EntityManager to a non container managed method

From: <glassfish_at_javadesktop.org>
Date: Thu, 17 May 2007 12:14:39 PDT

Hello,

I am running a little test:

* I have a static method that is not container managed, that takes an EntityManager as a parameter and does a find on an entity, given some other parameters. This method is passed an EntityManager from a session bean that is container managed, and injects EntityManager with its persistence context.

When I test this, I get an OptimisticLockException. I know that in EJB 3.0, we should not need to pass EntityManager as a parameter, as it is implicit in the transaction context.

I believe this logic must be in session bean that has an injected EntityManager also, and the method should be annotated to allow it to join the transaction context of the calling bean. This would allow it to have the persistence context of the calling bean and do the find.

Is this correct, or is there any way to use EntityManager by passing it to a non-container managed method?

Thanks,

Andrew
[Message sent by forum member 'asmithgf' (asmithgf)]

http://forums.java.net/jive/thread.jspa?messageID=217706