users@glassfish.java.net

Re: EntityManager Lookup via JNDI in Glassfish

From: Aleksandras Novikovas <an_at_systemtier.com>
Date: Thu, 19 Mar 2009 02:43:34 +0200

Why do you need EntityManager in POJO?

If you really need it - use injection in your EJB:
    @PersistenceContext (unitName = "myPU")
    private EntityManager em;

and then pass it as parameter to constructor or other method.

-
Aleksandras Novikovas



On Wed, 2009-03-18 at 17:17 -0700, glassfish_at_javadesktop.org wrote:
> I'm looking for a way to get an EntityManager into a POJO running in Glassfish. I'd like to do the lookup via JNDI but can't seem to find a way to get GF to provide an EntityManager.
>
> The app is a collection of EJBs, POJOs, and Entities. There is no web tier.
>
> I've tried this:
>
> try {
> Context ic = (Context) new InitialContext();
> this.em = (EntityManager) ic.lookup("java:comp/env/persistence/em");
> } catch (NamingException ne) {
> throw new MorissRuntimeException("Problem obtaining EntityManager", ne);
> }
>
> but no luck. Any ideas or suggestions?
>
> Thanks,
>
> -zach
> [Message sent by forum member 'euqaz' (euqaz)]
>
> http://forums.java.net/jive/thread.jspa?messageID=337824
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>