users@glassfish.java.net

Obtain embedded EJB container EntityManager in TestNG test

From: <glassfish_at_javadesktop.org>
Date: Sat, 27 Feb 2010 01:25:41 PST

Hi All,

I have a testng test that starts the Glassfish EJB 3.1 embedded container, looks up a stateless session bean using JNDI and invokes a method that persists an entity.

I'd like to get hold of the entity manager within my test so that I can query the database to verify the results. The problem is I can't seem to get a handle on the container managed entity manager that is injected into the stateless EJB.

I've tried many variations of JNDI names to look it up. I've even tried using Persistence.createEntityManagerFactory which provides an EntityManager but not the same one as the container so the expected results are not returned.

So, my question is; Is it possible to lookup the container managed entity manager when using glassfish embedded EJB3.1 container?
If so, what is the JNDI name I should use?
[Message sent by forum member 'monkeyphonics' (ben.dherville_at_gmail.com)]

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