-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: Problem: Schema update closes session
PostPosted: Mon Oct 24, 2005 9:12 am 
Newbie

Joined: Thu Oct 13, 2005 11:43 am
Posts: 11
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" />


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 10:45 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 1:03 pm
Posts: 38
check your hibernate.properties file and make sure you aren't specifying auto close.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 2:23 am 
Newbie

Joined: Thu Oct 13, 2005 11:43 am
Posts: 11
sarahsmith_books wrote:
check your hibernate.properties file and make sure you aren't specifying auto close.

Thanks for the reply. But I don't have auto close in my configuration, see my hibernate.cfg.xml above.
Someone else got an idea?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 4:01 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
But do you have a hibernate.properties that might specify auto close. They are two different files.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 4:19 am 
Newbie

Joined: Thu Oct 13, 2005 11:43 am
Posts: 11
jamie_dainton wrote:
But do you have a hibernate.properties that might specify auto close. They are two different files.

Jamie, I decided to use the xml configuration so I don't have the hibernate.properties. Also I don't configure any properties in my application.

My problem still exists, but thanks for trying to help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 8:53 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 1:03 pm
Posts: 38
Looking at the stack trace, it looks like everything is null, including your driver connection source. Are you sure you have the driver available that you are trying to use?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 9:54 am 
Newbie

Joined: Thu Oct 13, 2005 11:43 am
Posts: 11
sarahsmith_books wrote:
Looking at the stack trace, it looks like everything is null, including your driver connection source. Are you sure you have the driver available that you are trying to use?

Well I think so: When I set hibernate.hbm2ddl.auto to create or off it works fine.

Still I wasn't able to debug the schema creation to see where the connection pool is closed. When I try to step in all the schema creation runs at once, not letting me step through. Strange thing ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 1:14 pm 
Newbie

Joined: Sun May 15, 2005 12:01 am
Posts: 8
You're not alone. I just ran into this too! Did you find a solution?

Everything was fine until I tried to switch to the c3p0 pool (from the hibernate built-in pool)

I hadn't noticed the hbm2ddl.auto until I saw your post. Sure enough, changing from update to create made it work again... arrgh.

I'm using:

postgres 8.0.4
hibernate 3.1rc2
c3p0 0.9.0.2


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 6:17 am 
Newbie

Joined: Thu Oct 13, 2005 11:43 am
Posts: 11
cwhite102 wrote:
You're not alone. I just ran into this too! Did you find a solution?

Everything was fine until I tried to switch to the c3p0 pool (from the hibernate built-in pool)

I hadn't noticed the hbm2ddl.auto until I saw your post. Sure enough, changing from update to create made it work again... arrgh.

I'm using:

postgres 8.0.4
hibernate 3.1rc2
c3p0 0.9.0.2


I didn't found a solution yet. Could it be caused by the underlying database since we are both using postgres? Are you able to switch your database (just for testing, maybe to HSQLDB)?

Let me know if you succeed.

I read somewhere that schema-update on runtime is not the best thing to do, so I decided to set hbm2ddl.auto to off. Now I have to create the schema by "hand" when I intall my application.

_________________
PS: Don't forget the credit system ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 2:47 pm 
Newbie

Joined: Sun May 15, 2005 12:01 am
Posts: 8
Deepthought wrote:
I didn't found a solution yet. Could it be caused by the underlying database since we are both using postgres? Are you able to switch your database (just for testing, maybe to HSQLDB)?

Let me know if you succeed.

I read somewhere that schema-update on runtime is not the best thing to do, so I decided to set hbm2ddl.auto to off. Now I have to create the schema by "hand" when I intall my application.



I just tried Oracle 10.2 and got the same error / behaviour.

I'll post in the C3P0 forums to draw attention to this thread...

My particular app would really like to use hbm2ddl.auto=update and not just during dev. Do you remember where you read it shouldn't be used?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 4:09 pm 
Newbie

Joined: Sun May 15, 2005 12:01 am
Posts: 8
Workaround - The problem only shows up when update is specified in the hibernate.cfg.xml file. If you do it in code it works fine...

Code:
<property name="hbm2ddl.auto">update</property>

vs.

new SchemaUpdate( cfg ).execute( true, true );


Top
 Profile  
 
 Post subject: another workaround
PostPosted: Tue Jan 17, 2006 8:13 pm 
Newbie

Joined: Tue Jan 17, 2006 11:27 am
Posts: 1
I had this problem today after switching to c3p0 from DBCP because DBCP didn't seem to be able to recover from the annoying MySQL auto-connection-drop "feature"... (and incidentally c3p0 has been quite a pain in the butt --- it sems a little immature to be the Hibernate-blessed pooling solution!)

Configuring c3p0 from JNDI (in my situation, with Tomcat, in META-INF/context.xml) instead of in hibernate.cfg.xml allows the hbm2ddl.auto=update to function without disrupting the application's acquisition of JDBC connections from the pool.


Of course, now when I redeploy my app (which since I'm developing it, I do frequently) I eventually run into "no more database connections available" from my database because someone (I'm assuming it's c3p0 at this point) isn't letting go of old database connections.... but it does solve the original hbm2ddl problem.

Maybe this won't be of much help since it introduces a problem as it solves another, but it's another datapoint.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.