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

Reply via email to