Actually not sure it should return null. I could be wrong (Andrea Boriero correct me if I am) but I think the TCK requires that the Transaction be available after the EntityManager is closed. I seem to recall having to change that in the past to cater to that expectation in the TCK.
True that the entity manager doesn't close immediately when EntityManager.close() is called if is enlisted in a JTA transaction (instead the close is delayed until the transaction completes, I think currently handled via Synchronization.afterCompletion()). From the JPA 2.2 spec section 7.7:
The EntityManager.close method closes an entity manager to release its persistence context and other resources. After calling close, the application must not invoke any further methods on the
EntityManager instance except for getTransaction and isOpen, or the IllegalStateException will be thrown. If the close method is invoked when a transaction is active, the persistence context remains managed until the transaction completes.
|