Calling getTransaction() on a closed Session should not throw ISE

Description

Calling getTransaction() on an already closed (app managed) entity manager shouldn't throw IllegalStateException, instead we should return an EntityTransaction.

Looking at the 5.1 org.hibernate.jpa.spi.AbstractEntityManagerImpl, we simply had the following, which I think would return null if called on a closed app managed entity manager:

From EntityManager#close javadoc:

The exception call stack for the thrown ISE is:

java.lang.IllegalStateException: org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl@1038f80a is closed
[javatest.batch] 13:48:09,281 INFO [stdout] (Thread-127) at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.errorIfClosed(AbstractLogicalConnectionImplementor.java:37)
[javatest.batch] 13:48:09,281 INFO [stdout] (Thread-127) at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.getPhysicalJdbcTransaction(AbstractLogicalConnectionImplementor.java:31)
[javatest.batch] 13:48:09,281 INFO [stdout] (Thread-127) at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.getResourceLocalTransaction(JdbcCoordinatorImpl.java:489)
[javatest.batch] 13:48:09,281 INFO [stdout] (Thread-127) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.getTransactionDriverControl(JdbcResourceLocalTransactionCoordinatorImpl.java:93)
[javatest.batch] 13:48:09,281 INFO [stdout] (Thread-127) at org.hibernate.engine.transaction.internal.TransactionImpl.<init>(TransactionImpl.java:45)
[javatest.batch] 13:48:09,281 INFO [stdout] (Thread-127) at org.hibernate.internal.AbstractSharedSessionContract.accessTransaction(AbstractSharedSessionContract.java:399)
[javatest.batch] 13:48:09,281 INFO [stdout] (Thread-127) at org.hibernate.internal.AbstractSharedSessionContract.getTransaction(AbstractSharedSessionContract.java:390)
[javatest.batch] 13:48:09,282 INFO [stdout] (Thread-127) at org.hibernate.internal.AbstractSessionImpl.getTransaction(AbstractSessionImpl.java:23)

Environment

None

Status

Assignee

Steve Ebersole

Reporter

Scott Marlow

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major
Configure