Retained MutableEntityEntry leak in entity context causes application hang

Looking at the testsuite for EntityManager tests the EntityEntryContext will not be cleared after a Transaction.commit().

Why should the commit clear the EntityManager? There is a clear() method for that.

For instance, you can span an EntityManager over multiple successive JPA transactions.

Am I expected to re-open EntityManager occasionally to make this application stable?

Since you are running a batch processing task, the lifespan of an EnitityManager should span on one or more batches, but not for the entire duration of the batch processing task. You can either flush-clear-commit or just create a new EntityManager after processing every N items.

For more details about the best way to do batch processing with JPA and Hibernate, check out this article.