org.hibernate.exception.JDBCConnectionException: Unable to release JDBC Connection
Situation: I'm writing unit test for a DAO class, using Hibernate and Maven surefire. We decide to create a test_db from a test_template before the unit tests and drop the test_db after the tests.
After I finish the code and test it using mvn test, it succeeded when I only test one test class : mvn test -Dtest=com.package.DummyTest
but failed when I test all test classes: mvn test -Dtest=com.package.*Test
The setup(), teardown() and hibernate query methods as well as the error stack trace are showing below:
setUp()
@BeforeClass
public static void setUpJdbc() throws IOException, InterruptedException, SQLException
Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/default_db", "user_name", "pw");
Statement statement = c.createStatement();
statement.executeUpdate("create database test_db with template test_template;");
statement.close();
c.close();
tearDown()
@AfterClass
public static void tearDownJdbc() throws SQLException
Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/default_db", "user_name", "pw");
Statement statement = c.createStatement();
statement.executeUpdate("REVOKE CONNECT ON DATABASE test_db FROM public;");
statement.execute("SELECT pid, pg_terminate_backend(pid) n" +
"FROM pg_stat_activity n" +
"WHERE datname = 'test_db' AND pid <> pg_backend_pid();");
statement.executeUpdate("drop database if exists test_db;");
statement.close();
c.close();
Hibernate query method:
public List<Object> query(String sqlquery) throws DatabaseConnectionException
Session session = null;
Transaction transcation = null;
List<Object> sqlQueryResults = null;
try
session = factory.openSession();
transcation = session.beginTransaction();
Query query = session.createNativeQuery(sqlquery);
sqlQueryResults = query.list();
transcation.commit();
catch (SQLGrammarException e)
if (transcation != null)
transcation.rollback();
throw new DatabaseConnectionException();
catch (HibernateException e)
if (transcation != null)
transcation.rollback();
throw new DatabaseConnectionException();
finally
if (session != null)
session.close();
return sqlQueryResults;
I can't figure out what's going on here. It seems like I cannot run session.close() properly.
org.hibernate.exception.JDBCConnectionException: Unable to release JDBC Connection
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.releaseConnection(LogicalConnectionManagedImpl.java:199)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.close(LogicalConnectionManagedImpl.java:239)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.close(JdbcCoordinatorImpl.java:189)
at org.hibernate.internal.AbstractSharedSessionContract.close(AbstractSharedSessionContract.java:311)
at org.hibernate.internal.SessionImpl.close(SessionImpl.java:423)
at com.dummy.DataLayer.query(DataLayer.java:173)
at com.dummy.MITypeCompositeDAO.getLatestExecutionForUser(MITypeCompositeDAO.java:71)
at com.dummy.MITypeCompositeDAO.getMITypeCompositeForUser(MITypeCompositeDAO.java:137)
at com.dummy.MITypeCompositeDAOTest.testGetMITypeCompositeForUser(MITypeCompositeDAOTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:369)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:275)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:239)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:160)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:373)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:334)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:119)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:407)
Caused by: org.postgresql.util.PSQLException: This connection has been closed.
at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:766)
at org.postgresql.jdbc.PgConnection.setAutoCommit(PgConnection.java:712)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.add(PooledConnections.java:68)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.closeConnection(DriverManagerConnectionProviderImpl.java:195)
at org.hibernate.internal.NonContextualJdbcConnectionAccess.releaseConnection(NonContextualJdbcConnectionAccess.java:46)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.releaseConnection(LogicalConnectionManagedImpl.java:196)
... 35 more
The situation is kind of complicated, so if you need more information please let me know.
I'm open to any opinions and advices and I'm willing to try all the you provide. Thanks in advance!
java postgresql hibernate jdbc
add a comment |
Situation: I'm writing unit test for a DAO class, using Hibernate and Maven surefire. We decide to create a test_db from a test_template before the unit tests and drop the test_db after the tests.
After I finish the code and test it using mvn test, it succeeded when I only test one test class : mvn test -Dtest=com.package.DummyTest
but failed when I test all test classes: mvn test -Dtest=com.package.*Test
The setup(), teardown() and hibernate query methods as well as the error stack trace are showing below:
setUp()
@BeforeClass
public static void setUpJdbc() throws IOException, InterruptedException, SQLException
Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/default_db", "user_name", "pw");
Statement statement = c.createStatement();
statement.executeUpdate("create database test_db with template test_template;");
statement.close();
c.close();
tearDown()
@AfterClass
public static void tearDownJdbc() throws SQLException
Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/default_db", "user_name", "pw");
Statement statement = c.createStatement();
statement.executeUpdate("REVOKE CONNECT ON DATABASE test_db FROM public;");
statement.execute("SELECT pid, pg_terminate_backend(pid) n" +
"FROM pg_stat_activity n" +
"WHERE datname = 'test_db' AND pid <> pg_backend_pid();");
statement.executeUpdate("drop database if exists test_db;");
statement.close();
c.close();
Hibernate query method:
public List<Object> query(String sqlquery) throws DatabaseConnectionException
Session session = null;
Transaction transcation = null;
List<Object> sqlQueryResults = null;
try
session = factory.openSession();
transcation = session.beginTransaction();
Query query = session.createNativeQuery(sqlquery);
sqlQueryResults = query.list();
transcation.commit();
catch (SQLGrammarException e)
if (transcation != null)
transcation.rollback();
throw new DatabaseConnectionException();
catch (HibernateException e)
if (transcation != null)
transcation.rollback();
throw new DatabaseConnectionException();
finally
if (session != null)
session.close();
return sqlQueryResults;
I can't figure out what's going on here. It seems like I cannot run session.close() properly.
org.hibernate.exception.JDBCConnectionException: Unable to release JDBC Connection
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.releaseConnection(LogicalConnectionManagedImpl.java:199)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.close(LogicalConnectionManagedImpl.java:239)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.close(JdbcCoordinatorImpl.java:189)
at org.hibernate.internal.AbstractSharedSessionContract.close(AbstractSharedSessionContract.java:311)
at org.hibernate.internal.SessionImpl.close(SessionImpl.java:423)
at com.dummy.DataLayer.query(DataLayer.java:173)
at com.dummy.MITypeCompositeDAO.getLatestExecutionForUser(MITypeCompositeDAO.java:71)
at com.dummy.MITypeCompositeDAO.getMITypeCompositeForUser(MITypeCompositeDAO.java:137)
at com.dummy.MITypeCompositeDAOTest.testGetMITypeCompositeForUser(MITypeCompositeDAOTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:369)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:275)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:239)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:160)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:373)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:334)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:119)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:407)
Caused by: org.postgresql.util.PSQLException: This connection has been closed.
at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:766)
at org.postgresql.jdbc.PgConnection.setAutoCommit(PgConnection.java:712)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.add(PooledConnections.java:68)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.closeConnection(DriverManagerConnectionProviderImpl.java:195)
at org.hibernate.internal.NonContextualJdbcConnectionAccess.releaseConnection(NonContextualJdbcConnectionAccess.java:46)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.releaseConnection(LogicalConnectionManagedImpl.java:196)
... 35 more
The situation is kind of complicated, so if you need more information please let me know.
I'm open to any opinions and advices and I'm willing to try all the you provide. Thanks in advance!
java postgresql hibernate jdbc
FYI: if I comment out the setUp() and tearDown() methods and dump the database manually before I runmvn test -Dtest=com.package.*Test, no exceptions was thrown. But that's not what we need, we would like to have a static test_db, which means we reset every time we manipulate the database.
– Xiangyu Zhao
Nov 12 '18 at 22:09
add a comment |
Situation: I'm writing unit test for a DAO class, using Hibernate and Maven surefire. We decide to create a test_db from a test_template before the unit tests and drop the test_db after the tests.
After I finish the code and test it using mvn test, it succeeded when I only test one test class : mvn test -Dtest=com.package.DummyTest
but failed when I test all test classes: mvn test -Dtest=com.package.*Test
The setup(), teardown() and hibernate query methods as well as the error stack trace are showing below:
setUp()
@BeforeClass
public static void setUpJdbc() throws IOException, InterruptedException, SQLException
Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/default_db", "user_name", "pw");
Statement statement = c.createStatement();
statement.executeUpdate("create database test_db with template test_template;");
statement.close();
c.close();
tearDown()
@AfterClass
public static void tearDownJdbc() throws SQLException
Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/default_db", "user_name", "pw");
Statement statement = c.createStatement();
statement.executeUpdate("REVOKE CONNECT ON DATABASE test_db FROM public;");
statement.execute("SELECT pid, pg_terminate_backend(pid) n" +
"FROM pg_stat_activity n" +
"WHERE datname = 'test_db' AND pid <> pg_backend_pid();");
statement.executeUpdate("drop database if exists test_db;");
statement.close();
c.close();
Hibernate query method:
public List<Object> query(String sqlquery) throws DatabaseConnectionException
Session session = null;
Transaction transcation = null;
List<Object> sqlQueryResults = null;
try
session = factory.openSession();
transcation = session.beginTransaction();
Query query = session.createNativeQuery(sqlquery);
sqlQueryResults = query.list();
transcation.commit();
catch (SQLGrammarException e)
if (transcation != null)
transcation.rollback();
throw new DatabaseConnectionException();
catch (HibernateException e)
if (transcation != null)
transcation.rollback();
throw new DatabaseConnectionException();
finally
if (session != null)
session.close();
return sqlQueryResults;
I can't figure out what's going on here. It seems like I cannot run session.close() properly.
org.hibernate.exception.JDBCConnectionException: Unable to release JDBC Connection
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.releaseConnection(LogicalConnectionManagedImpl.java:199)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.close(LogicalConnectionManagedImpl.java:239)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.close(JdbcCoordinatorImpl.java:189)
at org.hibernate.internal.AbstractSharedSessionContract.close(AbstractSharedSessionContract.java:311)
at org.hibernate.internal.SessionImpl.close(SessionImpl.java:423)
at com.dummy.DataLayer.query(DataLayer.java:173)
at com.dummy.MITypeCompositeDAO.getLatestExecutionForUser(MITypeCompositeDAO.java:71)
at com.dummy.MITypeCompositeDAO.getMITypeCompositeForUser(MITypeCompositeDAO.java:137)
at com.dummy.MITypeCompositeDAOTest.testGetMITypeCompositeForUser(MITypeCompositeDAOTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:369)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:275)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:239)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:160)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:373)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:334)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:119)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:407)
Caused by: org.postgresql.util.PSQLException: This connection has been closed.
at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:766)
at org.postgresql.jdbc.PgConnection.setAutoCommit(PgConnection.java:712)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.add(PooledConnections.java:68)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.closeConnection(DriverManagerConnectionProviderImpl.java:195)
at org.hibernate.internal.NonContextualJdbcConnectionAccess.releaseConnection(NonContextualJdbcConnectionAccess.java:46)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.releaseConnection(LogicalConnectionManagedImpl.java:196)
... 35 more
The situation is kind of complicated, so if you need more information please let me know.
I'm open to any opinions and advices and I'm willing to try all the you provide. Thanks in advance!
java postgresql hibernate jdbc
Situation: I'm writing unit test for a DAO class, using Hibernate and Maven surefire. We decide to create a test_db from a test_template before the unit tests and drop the test_db after the tests.
After I finish the code and test it using mvn test, it succeeded when I only test one test class : mvn test -Dtest=com.package.DummyTest
but failed when I test all test classes: mvn test -Dtest=com.package.*Test
The setup(), teardown() and hibernate query methods as well as the error stack trace are showing below:
setUp()
@BeforeClass
public static void setUpJdbc() throws IOException, InterruptedException, SQLException
Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/default_db", "user_name", "pw");
Statement statement = c.createStatement();
statement.executeUpdate("create database test_db with template test_template;");
statement.close();
c.close();
tearDown()
@AfterClass
public static void tearDownJdbc() throws SQLException
Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/default_db", "user_name", "pw");
Statement statement = c.createStatement();
statement.executeUpdate("REVOKE CONNECT ON DATABASE test_db FROM public;");
statement.execute("SELECT pid, pg_terminate_backend(pid) n" +
"FROM pg_stat_activity n" +
"WHERE datname = 'test_db' AND pid <> pg_backend_pid();");
statement.executeUpdate("drop database if exists test_db;");
statement.close();
c.close();
Hibernate query method:
public List<Object> query(String sqlquery) throws DatabaseConnectionException
Session session = null;
Transaction transcation = null;
List<Object> sqlQueryResults = null;
try
session = factory.openSession();
transcation = session.beginTransaction();
Query query = session.createNativeQuery(sqlquery);
sqlQueryResults = query.list();
transcation.commit();
catch (SQLGrammarException e)
if (transcation != null)
transcation.rollback();
throw new DatabaseConnectionException();
catch (HibernateException e)
if (transcation != null)
transcation.rollback();
throw new DatabaseConnectionException();
finally
if (session != null)
session.close();
return sqlQueryResults;
I can't figure out what's going on here. It seems like I cannot run session.close() properly.
org.hibernate.exception.JDBCConnectionException: Unable to release JDBC Connection
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.releaseConnection(LogicalConnectionManagedImpl.java:199)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.close(LogicalConnectionManagedImpl.java:239)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.close(JdbcCoordinatorImpl.java:189)
at org.hibernate.internal.AbstractSharedSessionContract.close(AbstractSharedSessionContract.java:311)
at org.hibernate.internal.SessionImpl.close(SessionImpl.java:423)
at com.dummy.DataLayer.query(DataLayer.java:173)
at com.dummy.MITypeCompositeDAO.getLatestExecutionForUser(MITypeCompositeDAO.java:71)
at com.dummy.MITypeCompositeDAO.getMITypeCompositeForUser(MITypeCompositeDAO.java:137)
at com.dummy.MITypeCompositeDAOTest.testGetMITypeCompositeForUser(MITypeCompositeDAOTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:369)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:275)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:239)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:160)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:373)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:334)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:119)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:407)
Caused by: org.postgresql.util.PSQLException: This connection has been closed.
at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:766)
at org.postgresql.jdbc.PgConnection.setAutoCommit(PgConnection.java:712)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.add(PooledConnections.java:68)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.closeConnection(DriverManagerConnectionProviderImpl.java:195)
at org.hibernate.internal.NonContextualJdbcConnectionAccess.releaseConnection(NonContextualJdbcConnectionAccess.java:46)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.releaseConnection(LogicalConnectionManagedImpl.java:196)
... 35 more
The situation is kind of complicated, so if you need more information please let me know.
I'm open to any opinions and advices and I'm willing to try all the you provide. Thanks in advance!
java postgresql hibernate jdbc
java postgresql hibernate jdbc
edited Nov 12 '18 at 21:58
asked Nov 12 '18 at 21:00
Xiangyu Zhao
54
54
FYI: if I comment out the setUp() and tearDown() methods and dump the database manually before I runmvn test -Dtest=com.package.*Test, no exceptions was thrown. But that's not what we need, we would like to have a static test_db, which means we reset every time we manipulate the database.
– Xiangyu Zhao
Nov 12 '18 at 22:09
add a comment |
FYI: if I comment out the setUp() and tearDown() methods and dump the database manually before I runmvn test -Dtest=com.package.*Test, no exceptions was thrown. But that's not what we need, we would like to have a static test_db, which means we reset every time we manipulate the database.
– Xiangyu Zhao
Nov 12 '18 at 22:09
FYI: if I comment out the setUp() and tearDown() methods and dump the database manually before I run
mvn test -Dtest=com.package.*Test, no exceptions was thrown. But that's not what we need, we would like to have a static test_db, which means we reset every time we manipulate the database.– Xiangyu Zhao
Nov 12 '18 at 22:09
FYI: if I comment out the setUp() and tearDown() methods and dump the database manually before I run
mvn test -Dtest=com.package.*Test, no exceptions was thrown. But that's not what we need, we would like to have a static test_db, which means we reset every time we manipulate the database.– Xiangyu Zhao
Nov 12 '18 at 22:09
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270035%2forg-hibernate-exception-jdbcconnectionexception-unable-to-release-jdbc-connecti%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270035%2forg-hibernate-exception-jdbcconnectionexception-unable-to-release-jdbc-connecti%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
FYI: if I comment out the setUp() and tearDown() methods and dump the database manually before I run
mvn test -Dtest=com.package.*Test, no exceptions was thrown. But that's not what we need, we would like to have a static test_db, which means we reset every time we manipulate the database.– Xiangyu Zhao
Nov 12 '18 at 22:09