Exceptions mark the transaction rollback-only; closed EntityManager checks
As required by section 3.3.7.1 of the specification, every RuntimeException raised by an EntityManager or Query method now marks the active transaction for rollback, except NoResultException, NonUniqueResultException, LockTimeoutException and QueryTimeoutException.
In previous releases the transaction remained committable after, for example, an IllegalArgumentException from find(), createNamedQuery() or an invalid CriteriaQuery.
Applications that caught such an exception and committed the same transaction now receive a RollbackException and must restart the transaction.
Operations on a closed EntityManager or its Query objects now consistently throw IllegalStateException.
This includes getEntityManagerFactory(), getCriteriaBuilder(), getMetamodel(), getDelegate(), setProperty(), isJoinedToTransaction(), createEntityGraph(), createQuery(CriteriaQuery) and Query.getHints(), getLockMode(), closeAll() and the parameter accessors, which used to work on a closed EntityManager.
Further changes: getLockMode()/setLockMode() on a bulk UPDATE/DELETE query and executeUpdate() on a SELECT query throw IllegalStateException; createQuery(CriteriaQuery) snapshots the criteria state, so modifying the CriteriaQuery afterwards no longer affects the created Query; isJoinedToTransaction() returns true for an active resource-local transaction.