Persistence thought of the day
By Marina Vatkina on Nov 19, 2006
The Java Persistence API defines an EntityManager.close method. After this method is called on an entity manager instance, it is still possible to call methods isOpen and getTransaction on that instance.
While it's clear why the former is allowed, the same requirement for the getTransaction method sounds strange at first glance. For the answer, let's look in the spec itself. In the section 3.1.1 EntityManager Interface, the javadoc for the EntityManager.close contains the following text:
If this method is called when the EntityManager is associated
with an active transaction, the persistence context remains
managed until the transaction completes.
This means that by allowing to call this method on a closed entity manager, the spec allows you to check the status and complete the transaction. (Of course this is all about the resource-local entity manager.)
Let me know, if it's still not clear...