openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dain Sundstrom <d...@iq80.com>
Subject EntityManager usage pattern
Date Sun, 10 Dec 2006 01:44:23 GMT
Based on the feed back I got on the "Flush all caches" thread, I  
wanted to clarify the preferred usage pattern for EntityManager.  Abe  
White said, "You must use a new EntityManager for each test" and I'm  
not sure if that was advice for my specific use case, or if in  
general, I should create a new entity manager instance for each  
transaction and close it when the transaction terminates.  Basically,  
something like this:

public void doWork() {
   beginTx()
   try {
     em = emf.createEntityManager()
     doSomething()
   } finally {
     completeTx()
     em.close()
   }
}

-dain

Mime
View raw message