Hi, You can get the EntityManager injected in your test case (as in a session bean). Here is the documentation http://openejb.apache.org/3.0/local-client-injection.html http://openejb.apache.org/3.0/local-client-injection.html
The second way consists in obtaining the entity manager using a JNDI lookup. The trick is that the name is not easy to guess. Please dig into that http://www.nabble.com/Obtaining-EntityManager-programatically-for-test-purposes-td21810387.html#a21883934 http://www.nabble.com/Obtaining-EntityManager-programatically-for-test-purposes-td21810387.html#a21883934 Hope it helps. Jean-Louis thejav wrote: > > I would like to run a JUnit test and access the EntityManager of the EJB I > am unit testing in order to persist some records in my Unit Test. The > EntityManager in the SessionBean that is being tested has a name defined > by: @PersistenceContext(name="foo", unitName="bar"). I then try to > retrieve the EntityManager using the name via a jndi lookup but i am > unable to retrieve the EntityManager. > > Is there another way to do this? > > How can i persist data in my UnitTest via JPA? > -- View this message in context: http://www.nabble.com/JPA-from-Unit-Test-tp25645402p25652737.html Sent from the OpenEJB User mailing list archive at Nabble.com.
