Uploaded image for project: 'Hibernate ORM'
  1. HHH-12487

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


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects versions: None
    • Fix versions: 5.3.0.CR2
    • Components: hibernate-core
    • Labels:
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
    • Sprint:


      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:

      public EntityTransaction getTransaction() {
      	if ( transactionType == PersistenceUnitTransactionType.JTA ) {
      		throw new IllegalStateException( "A JTA EntityManager cannot use getTransaction()" );
      	return tx;

      From EntityManager#close javadoc:

      Close an application-managed entity manager. After the close method has been invoked, all methods on the EntityManager instance and any Query, TypedQuery, and StoredProcedureQuery objects obtained from it will throw the IllegalStateException except for getProperties, getTransaction, and isOpen (which will return false). If this method is called when the entity manager is joined to an active transaction, the persistence context remains managed until the transaction completes.

      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)




            • Votes:
              0 Vote for this issue
              4 Start watching this issue


              • Created: