> EntityManagerFactory emf =
OpenJPAPersistence.createEntityManagerFactory(EMF_JNDI_LOCATION,
(Context) null);
1. Instead of passing null context, if the same Context instance is
passed on every invocation -- does the behaviour change?
2. If the emf and its underlying brokerfactory bf from two consecutive
invocation are emf1,bf1 and emf2, bf2 then which of the following are
true?
     a) emf1 == emf2  and bf1 == bf2
     b).  emf1 != emf2 but bf1 == bf2
     c).  emf1!=emf2 and bf1!=bf2



Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: Hans J. Prueller [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 27, 2007 10:30 PM
To: open-jpa-dev@incubator.apache.org
Subject: AW: EMF JNDI lookup is starting openJPA every time - was: Howto
integrate JPA within EJB2.1 session beans? 

please see below. The method PersistenceService.getEntityManager() is
invoked directly in SLSB's methods if access to the EM is needed, so
there could be multiple invocations within a single transaction spanning
multiple SLSB methods.

hth,
Hans

public class PersistenceService {
        private static final Logger logger =
Logger.getLogger(PersistenceService.class.getName());
        
        public static final String EMF_JNDI_LOCATION =
"your/EMF/JNDI/location";

        public static EntityManager getEntityManager() {
                
                logger.log(Level.FINEST, "creating a fresh, clean
EntityManager from JNDI EMF.");
                
                EntityManagerFactory emf = OpenJPAPersistence
        
.createEntityManagerFactory(EMF_JNDI_LOCATION, (Context) null);

                final BrokerFactory bf =
OpenJPAPersistence.toBrokerFactory(emf);

                final Broker b = bf.newBroker(bf.getConfiguration()
                                .getConnectionUserName(),
bf.getConfiguration()
                                .getConnectionPassword(), true,
bf.getConfiguration().getConnectionRetainModeConstant(), true); 
                // do some JPA configuration setup. Logic stolen from 
                // EntityManagerFactoryImpl.
                b.setAutoDetach(AutoDetach.DETACH_CLOSE, true);
                b.setAutoDetach(AutoDetach.DETACH_ROLLBACK, true);
                b.setDetachedNew(false);

                return OpenJPAPersistence.toEntityManager(b);

                        }
}



_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

Reply via email to