Sorry to insist about this, and I know it's very late in the day for
this version, but unless I've failed to see something this does look
like a stupid oversight that is very easily fixed.
EntityManager contains a close() method which has to be called on
anything returned by emf.createEntityManager().
If the words "implements AutoCloseable" were added to the declaration
of interface EntityManager then, without making any other changes, the
try-with-resources statement could be used to ensure closure in all
circumstances, thus:
try (EntityManager em = emf.createEntityManager()) {
// use em
}
This is now the preferred idiom for anything that requires a close
call.
The only down side I can see to this change is that it would tie JPA to
java 1.7 or later, since java.lang.AutoCloseable was only introduced in
this version, but that doesn't seem much of a problem.
Is there a good reason this hasn't been done?