-->
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: c3p0 PoolBackedDataSource closed() on beginTransaction
PostPosted: Mon Nov 08, 2010 8:16 am 
Newbie

Joined: Sat Sep 18, 2010 11:09 am
Posts: 2
I'm using the classic HibernateUtil with Hibernate 3.6.0Final and c3p0 0.9.1 (boundled with it).
When I do

Code:
   Session session = HibernateUtil.getSessionFactory().openSession();
   Transaction tx = session.beginTransaction();   
   List< .. > l = (List< .. >)session.createQuery(" ... ").list();
   tx.commit();
   session.close();
   HibernateUtil.shutdown();

   Session session = HibernateUtil.getSessionFactory().openSession();
   Transaction tx = session.beginTransaction();   
   List< .. > l = (List< .. >)session.createQuery(" ... ").list();
   tx.commit();
   session.close();
   HibernateUtil.shutdown();


the second session.beginTransaction() raises an SQLException from c3p0.

This was working fine in 3.3.2. I found many threads about closed() PoolBackedDataSources, but no solutions.

Please help!
Marco

Code:
Exception in thread "AWT-EventQueue-0" org.hibernate.exception.GenericJDBCException: Cannot open connection
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
   at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
   at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
   at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160)
   at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
   at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
   at (myapp)
   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.sql.SQLException: com.mchange.v2.c3p0.PoolBackedDataSource@aec7d9d6 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@dba6e7f2 [ 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 -> 1hge13a8cc0yolv1x95331|4d16318b, 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@8112f8b5 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1hge13a8cc0yolv1x95331|43f4ebd, jdbcUrl -> jdbc:postgresql:hostname, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1hge13a8cc0yolv1x95331|30b48b11, 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:78)
   at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
   ... 14 more


Code:
public class HibernateUtil {

   private static SessionFactory sessionFactory;

   static {
      try {
         sessionFactory = new Configuration().configure().buildSessionFactory();
         
      } catch (Throwable ex) {
         throw new ExceptionInInitializerError(ex);
      }
   }

   public static SessionFactory getSessionFactory() {
      // Alternatively, we could look up in JNDI here
      return sessionFactory;
   }

   public static void shutdown() {
      // Close caches and connection pools
      getSessionFactory().close();
   }
}


From my Hibernate configuration:
Code:
   <!-- Use the C3P0 connection pool provider -->
   <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
   <property name="hibernate.c3p0.min_size">5</property>
   <property name="hibernate.c3p0.max_size">20</property>
   <property name="hibernate.c3p0.timeout">300</property>
   <property name="hibernate.c3p0.max_statements">50</property>
   <property name="hibernate.c3p0.idle_test_period">3000</property>


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.