users@glassfish.java.net

Re: Embedded EJB JNDI question

From: Marina Vatkina <marina.vatkina_at_oracle.com>
Date: Mon, 02 May 2011 17:47:19 -0700

EM/EMF are available for a lookup only inside a component, like an EJB,
but not a Java SE client.

-marina

NBW wrote:
> I have a JUnit test that sparks up an Embedded EJBContainer. I can
> look up a SSB with the following:
>
> Map<String, Object> p = new HashMap<String, Object>();
> p.put(EJBContainer.APP_NAME, "myApp");
> p.put(EJBContainer.MODULES, new File("out/prod/MYAPP");
> p.put("org.glassfish.ejb.embedded.glassfish.installation.root",
> "C:/glassfish3/glassfish");
> EJBContainer ejbC = EJBContainer.createEJBContainer(p);
> Context ctx = ejbC.getContext();
>
> (MySSB)ctx.lookup("java:global/myApp/MYAPP/MySSB");
>
> The MODULES path also contains a persistence.xml which defines a JTA
> datasource like so:
>
> <persistence-unit name="FOO" transaction-type="JTA">
> <jta-data-source>jdbc/__embeddedMYAPP</jta-data-source>
> ....
>
> My question is, what would be the correct JNDI lookup string to use
> with ctx above to get a reference to the EntityManagerFactory and/or
> EntityManager provided by this PU? I've tried various things but so
> far no dice (eg: "java:global/myApp/MYAPP/jdbc/__embeddedMYAPP"
> fails). Thanks,
>
> -Noah