• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception on SessionFactory.close()

 
Marcin Mogiela
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I invoke close on SessionFactory I get an exception:

java.sql.SQLException: com.mchange.v2.c3p0.PoolBackedDataSource@95504d20 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@fa5ceb37 [ 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 -> 2wf6bc7u12tsfuthqwmyv|fa5ff3, idleConnectionTestPeriod -> 3000, initialPoolSize -> 2, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 5000, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 2, maxStatements -> 100, maxStatementsPerConnection -> 0, minPoolSize -> 2, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@48c6ef14 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 2wf6bc7u12tsfuthqwmyv|8acfc3, jdbcUrl -> jdbc:mysql://localhost/examscam, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 2wf6bc7u12tsfuthqwmyv|1238785, 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.AbstractPoolBackedDa


hibernate.properties


my code:


Everything is ok when hibernate.c3p0.* properties are not set.
Do you know what might be the reason why it is not working?
[ June 15, 2008: Message edited by: Marcin Mogiela ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe, and this is a guess, is that c3po is trying to set up its connection pool with connections, but you close the sessionfactory before that can happen, so it is in C3PO that is saying "hey, I can't get to the SessionFactory anymore to find out what I need to get this connection pool started. The SessionFactory is telling me it is closed for business."

Remember there are possibly many threads at work, so the code you have runs one line right after the other while work behind it is being done.

Mark
 
Marcin Mogiela
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is strange. If it was about this multi threading thing I think the close method would not been implemented right. It could wait till it is possible to close.

I wanted to use ServletContextListener to build session factory on contextInitialized and close it on contextDestroyed which I thought was a good idea.

I am learning hibernate and tried to use this setting:
hibernate.hbm2ddl.auto=create-drop
to drop my schema after I stop Tomcat server.




But when I stop my Tomcat server it crashes.
Here are also the logs from log4j:
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While, I have never had to anything of the likes, but I would never try such a task as using the ServletContextListener. I think you might be tying stuff together that are apples and oranges.

I might make a bootstrap servlet/class that starts when the app is first deployed, but that doesn't require a ServletContextListener.

Actually, The practice is to have a Singleton HibernateUtil class that has one SessionFactory created.

On this link look at section 1.2.5
http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html

You can basically copy and paste that one.

Mark
 
Marcin Mogiela
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to my question:
"create-drop with c3p0 causes SQLException"

There is a bug in hibernate. Today I found the description on http://opensource.atlassian.com/projects/hibernate/browse/HHH-2694

I still have a question about this practice of using HibernateUtil class.

Why is such class not provided by the framewordk out of the box? On every tutorial there are descriptions of SessionFactory, Configuration, etc classes, and then HibernateUtil is introduced that hides the details. Wouldn't the api be simpler if there was only one HibernateUtil class for us to use?
Perhaps these classes gives us more flexibility but isn't it lost by having HibernateUtil class?

Thanks,
Marcin
[ June 17, 2008: Message edited by: Marcin Mogiela ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic