8.7. Closing

public boolean isOpen ();
public void close ();

When an EntityManager is no longer needed, you should call its close method. Closing an EntityManager releases any resources it is using. The persistence context ends, and the entities managed by the EntityManager become detached. Any Query instances the EntityManager created become invalid. Calling any method other than isOpen on a closed EntityManager results in an IllegalStateException. You cannot close an EntityManager that is in the middle of a transaction.

If you are in a managed environment using injected entity managers, you should not close them.


Skip navigation bar   Back to Top