-->
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.  [ 1 post ] 
Author Message
 Post subject: Exception when SessionFactory tries to drop schema
PostPosted: Tue May 08, 2007 6:19 pm 
Newbie

Joined: Tue May 08, 2007 4:37 pm
Posts: 2
This one is pobably for Hibernate developers as opposed to users.

As explained in Java Persistence with Hibernate, Chapter 2, create-drop value of hbm2ddl.auto property makes SessionFactory try to drop schema.

However, when this is combined the c3p0 pooling, it does not work.

Hibernate version: 3.2.2

Mapping extract: <property name="hibernate.hbm2ddl.auto">create-drop</property>

Full stack trace of any exception that occurs:
Code:
java.sql.SQLException: com.mchange.v2.c3p0.PoolBackedDataSource@d93e00d3 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@3322abf5 [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2zuhoi7mudjlrix26odx|9444d1, idleConnectionTestPeriod -> 3000, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 300, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@ed411466 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 2zuhoi7mudjlrix26odx|b1aebf, jdbcUrl -> jdbc:derby:helloworld;create=true, properties -> {} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 2zuhoi7mudjlrix26odx|12aea3e, numHelperThreads -> 3 ] has been closed() -- you can no longer use it.
   at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.assertCpds(AbstractPoolBackedDataSource.java:447)
   at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getPoolManager(AbstractPoolBackedDataSource.java:459)
   at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
   at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:56)
   at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
   at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
   at org.hibernate.tool.hbm2ddl.SchemaExport.drop(SchemaExport.java:143)
   at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:810)
   at persistence.HibernateUtil.shutdown(HibernateUtil.java:33)
   at hello.HelloWorld.main(HelloWorld.java:76)


Name and version of the database you are using:
Derby 10.2.2

Debug level Hibernate log excerpt:
Quote:
00:56:16,687 INFO SessionFactoryImpl:769 - closing
00:56:16,687 INFO SchemaExport:154 - Running hbm2ddl schema export
00:56:16,703 DEBUG SchemaExport:170 - import file not found: /import.sql
00:56:16,703 INFO SchemaExport:179 - exporting generated schema to database
00:56:16,703 ERROR SchemaExport:202 - schema export unsuccessful




Stepping into Hibernate code revealed the following code fragment

Code:
   public void close() throws HibernateException {

      log.info("closing");

      isClosed = true;

      Iterator iter = entityPersisters.values().iterator();
      while ( iter.hasNext() ) {
         EntityPersister p = (EntityPersister) iter.next();
         if ( p.hasCache() ) {
            p.getCache().destroy();
         }
      }

      iter = collectionPersisters.values().iterator();
      while ( iter.hasNext() ) {
         CollectionPersister p = (CollectionPersister) iter.next();
         if ( p.hasCache() ) {
            p.getCache().destroy();
         }
      }

      if ( settings.isQueryCacheEnabled() )  {
         queryCache.destroy();

         iter = queryCaches.values().iterator();
         while ( iter.hasNext() ) {
            QueryCache cache = (QueryCache) iter.next();
            cache.destroy();
         }
         updateTimestampsCache.destroy();
      }

      settings.getCacheProvider().stop();

      try {
         settings.getConnectionProvider().close();
      }
      finally {
         SessionFactoryObjectFactory.removeInstance(uuid, name, properties);
      }

      if ( settings.isAutoDropSchema() ) {
         schemaExport.drop( false, true );
      }
   }


The problem is that schemaExport.drop is called AFTER settings.getConnectionProvider().close and c3p0 datasource is already destroyed.

Am I missing something or create-drop will not work with c3p0?


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

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.