openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pinaki Poddar" <>
Subject RE: EMF JNDI lookup is starting openJPA every time - was: Howto integrate JPA within EJB2.1 session beans?
Date Wed, 28 Feb 2007 21:48:00 GMT
 > EntityManagerFactory emf =
(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
     a) emf1 == emf2  and bf1 == bf2
     b).  emf1 != emf2 but bf1 == bf2
     c).  emf1!=emf2 and bf1!=bf2

Pinaki Poddar
BEA Systems

-----Original Message-----
From: Hans J. Prueller [] 
Sent: Tuesday, February 27, 2007 10:30 PM
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.


public class PersistenceService {
	private static final Logger logger =
	public static final String 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 =

		final Broker b = bf.newBroker(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);

		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.

View raw message