java.sql.SQLException: Cannot close a connection while a transaction is still active.

Hibernate JIRA | Marcel | 1 year ago
  1. 0

    I have created a small demo application, where after creating an EntityManagerFactory and an EntityManager, I simply do a select query and then close the EntityManager first and then the EntityManagerFactory. But when closing the Factory, I get the following Exception: {code} java.sql.SQLException: Cannot close a connection while a transaction is still active. at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.checkForTransactionInProgress(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.close(Unknown Source) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.stop(DriverManagerConnectionProviderImpl.java:275) at org.hibernate.service.internal.AbstractServiceRegistryImpl.stopService(AbstractServiceRegistryImpl.java:360) at org.hibernate.service.internal.AbstractServiceRegistryImpl.destroy(AbstractServiceRegistryImpl.java:344) at org.hibernate.service.internal.AbstractServiceRegistryImpl.deRegisterChild(AbstractServiceRegistryImpl.java:393) at org.hibernate.service.internal.AbstractServiceRegistryImpl.destroy(AbstractServiceRegistryImpl.java:351) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$ServiceRegistryCloser.sessionFactoryClosed(EntityManagerFactoryBuilderImpl.java:842) at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryClosed(SessionFactoryObserverChain.java:48) at org.hibernate.internal.SessionFactoryImpl.close(SessionFactoryImpl.java:1066) at org.hibernate.jpa.internal.EntityManagerFactoryImpl.close(EntityManagerFactoryImpl.java:339) at com.stackoverflow.jpa.emf.close.example.Run.main(Run.java:24) Caused by: ERROR 25001: Cannot close a connection while a transaction is still active. at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source) ... 17 more {code} Since I do not use or need any transaction for a simply select query, I think that there might be an error in Hibernate. The Exception will *not* be raised, when I start a transaction before doing the select and close it afterwards. But it seems a bit strange, that I have to do a transaction for every select! See the attachement for the demo application.

    Hibernate JIRA | 1 year ago | Marcel
    java.sql.SQLException: Cannot close a connection while a transaction is still active.
  2. 0

    I have created a small demo application, where after creating an EntityManagerFactory and an EntityManager, I simply do a select query and then close the EntityManager first and then the EntityManagerFactory. But when closing the Factory, I get the following Exception: {code} java.sql.SQLException: Cannot close a connection while a transaction is still active. at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.checkForTransactionInProgress(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.close(Unknown Source) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.stop(DriverManagerConnectionProviderImpl.java:275) at org.hibernate.service.internal.AbstractServiceRegistryImpl.stopService(AbstractServiceRegistryImpl.java:360) at org.hibernate.service.internal.AbstractServiceRegistryImpl.destroy(AbstractServiceRegistryImpl.java:344) at org.hibernate.service.internal.AbstractServiceRegistryImpl.deRegisterChild(AbstractServiceRegistryImpl.java:393) at org.hibernate.service.internal.AbstractServiceRegistryImpl.destroy(AbstractServiceRegistryImpl.java:351) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$ServiceRegistryCloser.sessionFactoryClosed(EntityManagerFactoryBuilderImpl.java:842) at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryClosed(SessionFactoryObserverChain.java:48) at org.hibernate.internal.SessionFactoryImpl.close(SessionFactoryImpl.java:1066) at org.hibernate.jpa.internal.EntityManagerFactoryImpl.close(EntityManagerFactoryImpl.java:339) at com.stackoverflow.jpa.emf.close.example.Run.main(Run.java:24) Caused by: ERROR 25001: Cannot close a connection while a transaction is still active. at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source) ... 17 more {code} Since I do not use or need any transaction for a simply select query, I think that there might be an error in Hibernate. The Exception will *not* be raised, when I start a transaction before doing the select and close it afterwards. But it seems a bit strange, that I have to do a transaction for every select! See the attachement for the demo application.

    Hibernate JIRA | 1 year ago | Marcel
    java.sql.SQLException: Cannot close a connection while a transaction is still active.
  3. 0

    SQLException thrown when GETting a Beer object from the database

    GitHub | 2 years ago | jcoady9
    java.sql.SQLException: Cannot close a connection while a transaction is still active.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    SQLSyntaxException when posting new MixedDrink to database

    GitHub | 2 years ago | jcoady9
    java.sql.SQLException: Cannot close a connection while a transaction is still active.
  6. 0

    error with 'getMixedDrinkList'

    GitHub | 2 years ago | jcoady9
    java.sql.SQLException: Cannot close a connection while a transaction is still active.

  1. davidvanlaatum 1 times, last 1 month ago
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.sql.SQLException

    Cannot close a connection while a transaction is still active.

    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException()
  2. Derby
    EmbedConnection.close
    1. org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    2. org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    3. org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
    4. org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
    5. org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
    6. org.apache.derby.impl.jdbc.EmbedConnection.checkForTransactionInProgress(Unknown Source)
    7. org.apache.derby.impl.jdbc.EmbedConnection.close(Unknown Source)
    7 frames
  3. org.hibernate.engine
    DriverManagerConnectionProviderImpl.stop
    1. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.stop(DriverManagerConnectionProviderImpl.java:275)
    1 frame
  4. Hibernate
    AbstractServiceRegistryImpl.destroy
    1. org.hibernate.service.internal.AbstractServiceRegistryImpl.stopService(AbstractServiceRegistryImpl.java:360)
    2. org.hibernate.service.internal.AbstractServiceRegistryImpl.destroy(AbstractServiceRegistryImpl.java:344)
    3. org.hibernate.service.internal.AbstractServiceRegistryImpl.deRegisterChild(AbstractServiceRegistryImpl.java:393)
    4. org.hibernate.service.internal.AbstractServiceRegistryImpl.destroy(AbstractServiceRegistryImpl.java:351)
    4 frames
  5. org.hibernate.jpa
    EntityManagerFactoryBuilderImpl$ServiceRegistryCloser.sessionFactoryClosed
    1. org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$ServiceRegistryCloser.sessionFactoryClosed(EntityManagerFactoryBuilderImpl.java:842)
    1 frame
  6. Hibernate
    SessionFactoryImpl.close
    1. org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryClosed(SessionFactoryObserverChain.java:48)
    2. org.hibernate.internal.SessionFactoryImpl.close(SessionFactoryImpl.java:1066)
    2 frames
  7. org.hibernate.jpa
    EntityManagerFactoryImpl.close
    1. org.hibernate.jpa.internal.EntityManagerFactoryImpl.close(EntityManagerFactoryImpl.java:339)
    1 frame
  8. com.stackoverflow.jpa
    Run.main
    1. com.stackoverflow.jpa.emf.close.example.Run.main(Run.java:24)
    1 frame