I'm using Hibernate in a standalone application with a PostgreSQL database.
Using c3p0 and setting "hibernate.hbm2ddl.auto" to "update" I'm getting the exceptions shown below when trying to open a session.
When I change the parameter to "create" or "off" it works (if the schema exists).
Also using the build in hibernate connection pool it works (with update and create). My configuration is attached.
It's strange since the schema update itself seems to work. But when I try to access the session again it fails with "Cannot open connection".
Any help would be appreciated a lot!
Hibernate version: 3.0.5, 3.1 rc2
Code between sessionFactory.openSession() and session.close():
I'm using the HibernateUtil class from the Caveat Emptor example:
Code:
private void addDataSet()
{
Session session = null;
Transaction tx = null;
try
{
System.out.println("Get session!");
session = HibernateUtil.getCurrentSession(); <- Line 166, see Exception below
tx = session.beginTransaction();
} catch (HibernateException e)
{
System.err.println("HibernateException: " + e.getLocalizedMessage());
e.printStackTrace();
HibernateUtil.closeSession();
}
...
Full stack trace of any exception that occurs:Code:
...
DEBUG [SchemaUpdate] comment on table public.event is 'Base table for all events.'
...
INFO [SchemaUpdate] schema update complete
DEBUG [BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@1eb2c1b [managed: 10, unused: 9, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@b4e29b)
DEBUG [BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@1eb2c1b [managed: 9, unused: 8, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@b4e29b)
DEBUG [BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@1eb2c1b [managed: 7, unused: 7, excluded: 1] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@b4e29b)
DEBUG [BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@1eb2c1b [managed: 6, unused: 6, excluded: 1] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@b4e29b)
DEBUG [BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@1eb2c1b [managed: 5, unused: 5, excluded: 1] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@b4e29b)
DEBUG [BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@1eb2c1b [managed: 4, unused: 4, excluded: 1] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@b4e29b)
DEBUG [BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@1eb2c1b [managed: 3, unused: 3, excluded: 1] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@b4e29b)
DEBUG [BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@1eb2c1b [managed: 2, unused: 2, excluded: 1] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@b4e29b)
DEBUG [BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@1eb2c1b [managed: 1, unused: 1, excluded: 1] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@b4e29b)
DEBUG [BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@1eb2c1b [managed: 0, unused: 0, excluded: 1] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@b4e29b)
DEBUG [PoolBackedDataSource] com.mchange.v2.c3p0.PoolBackedDataSource@e6f7d2 has been closed. force_destroy == false
java.lang.Exception: Debug -- PoolBackedDataSource.close() stack trace.
at com.mchange.v2.c3p0.PoolBackedDataSource.close(PoolBackedDataSource.java:214)
at com.mchange.v2.c3p0.DataSources.destroy(DataSources.java:259)
at com.mchange.v2.c3p0.DataSources.destroy(DataSources.java:226)
at org.hibernate.connection.C3P0ConnectionProvider.close(C3P0ConnectionProvider.java:118)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:175)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:298)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1145)
at test.util.HibernateUtil.<clinit>(HibernateUtil.java:96)
at test.Test.addDataSet(Test.java:166)
at test.Test.start(Test.java:76)
at test.Test.main(Test.java:58)
INFO [SessionFactoryImpl] Checking 0 named queries
DEBUG [SessionImpl] opened session at timestamp: 4629122767474688
DEBUG [JDBCTransaction] begin
DEBUG [ConnectionManager] opening JDBC connection
DEBUG [JDBCExceptionReporter] Cannot open connection [???]
java.sql.SQLException: com.mchange.v2.c3p0.PoolBackedDataSource@e6f7d2 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@16e1fb1 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 16e1fb1, idleConnectionTestPeriod -> 30, initialPoolSize -> 10, maxIdleTime -> 30, maxPoolSize -> 100, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@15253d5 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 15253d5, jdbcUrl -> jdbc:postgresql://127.0.0.1:5432/mydb, properties -> {user=******, password=******, release_mode=on_close} ], preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ], factoryClassLocation -> null, identityToken -> e6f7d2, numHelperThreads -> 3 ] has been closed() -- you can no longer use it.
at com.mchange.v2.c3p0.PoolBackedDataSource.assertCpds(PoolBackedDataSource.java:234)
at com.mchange.v2.c3p0.PoolBackedDataSource.getPoolManager(PoolBackedDataSource.java:246)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:304)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:109)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:134)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1236)
at test.Test.addDataSet(Test.java:167)
at test.Test.start(Test.java:76)
at test.Test.main(Test.java:58)
WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
ERROR [JDBCExceptionReporter] com.mchange.v2.c3p0.PoolBackedDataSource@e6f7d2 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@16e1fb1 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 16e1fb1, idleConnectionTestPeriod -> 30, initialPoolSize -> 10, maxIdleTime -> 30, maxPoolSize -> 100, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@15253d5 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 15253d5, jdbcUrl -> jdbc:postgresql://127.0.0.1:5432/airportdb, properties -> {user=******, password=******, release_mode=on_close} ], preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ], factoryClassLocation -> null, identityToken -> e6f7d2, numHelperThreads -> 3 ] has been closed() -- you can no longer use it.
HibernateException: Cannot open connection
DEBUG [SessionImpl] setting flush mode to: AUTO
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:307)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:109)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:134)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1236)
at test.Test.addDataSet(Test.java:167)
at test.Test.start(Test.java:76)
at test.Test.main(Test.java:58)
Caused by: java.sql.SQLException: com.mchange.v2.c3p0.PoolBackedDataSource@e6f7d2 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@16e1fb1 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 16e1fb1, idleConnectionTestPeriod -> 30, initialPoolSize -> 10, maxIdleTime -> 30, maxPoolSize -> 100, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@15253d5 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 15253d5, jdbcUrl -> jdbc:postgresql://127.0.0.1:5432/airportdb, properties -> {user=******, password=******, release_mode=on_close} ], preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ], factoryClassLocation -> null, identityToken -> e6f7d2, numHelperThreads -> 3 ] has been closed() -- you can no longer use it.
at com.mchange.v2.c3p0.PoolBackedDataSource.assertCpds(PoolBackedDataSource.java:234)
at com.mchange.v2.c3p0.PoolBackedDataSource.getPoolManager(PoolBackedDataSource.java:246)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:304)
... 7 more
Name and version of the database you are using: PostgreSQL 8.0.4
Hibernate Configuration:Code:
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">****</property>
<property name="hibernate.connection.password">****</property>
<property name="hibernate.connection.url">jdbc:postgresql://127.0.0.1:5432/mydb</property>
<property name="hibernate.default_schema">public</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.jdbc.batch_size">20</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">30</property>
<property name="c3p0.max_size">100</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">30</property>
<mapping resource="test/Event.hbm.xml" />