users@glassfish.java.net

Re: Same app twice using JPA

From: <glassfish_at_javadesktop.org>
Date: Wed, 20 Jun 2007 12:38:33 PDT

No, that pattern is not recommended. It's better to use the Java EE approach, which is to
obtain container-managed EntityManagers using either

injection :

@PersistenceContext(unitName="GeDoc2PU")
private EntityManager em;

or lookup :

// put at class-level of a managed class
@PersistenceContext(name="myPU", unitName="GeDoc2PU")

then somewhere in the code :

InitialContext ic = new InitialContext();
EntityManager em = (EntityManager) ic.lookup("java:comp/env/myPU");

The approach you're using is too brittle and too tied to classloaders. Let the
application server manage resources.
[Message sent by forum member 'ksak' (ksak)]

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