Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes c3p0 configuration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "c3p0 configuration" Watch "c3p0 configuration" New topic

c3p0 configuration

Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
I have this problem: Our application is running on a tomcat 5.5 and uses hibernate with a mysql 5 database. It works great during office hours, but when we arrive in the morning, the tomcat is still running, but the database connections had been closed by the database. Hibernate doesn't know about this and tries to use them. If we reload the page after the exception we get, it starts working, because it creates new connections.
I've been reading about this ( and tried to configure c3p0 to handle this, but I get te same error. Also I don't know how to test this properly, so far I've been killing the connection thread with the mysql administrator.

This is the hibernate.cfg.xml

This is my, which is located in the src folder of the project (the root of all packages).. does it go there?

Is my configuration ok? How can I prevent this error from happening? If it does happen, how can I prevent the application from failing?
Thanks a lot.

2B || !2B
gustavo sanchez

Joined: May 18, 2007
Posts: 5
Im having the same problem, when i see the stack of tcp connections from tomcat to hibernate, all the connections are in "close wait" state.
I cant figure the reason, i hope someone can help !
Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
We modified the hibernate.cfg.xml to use a datasource, instead of passing the connection parameters there, and it seems to be working that way.
Unfortunatelly this is only a workaround and we still need to fix it the other way because we can't add datasources to the production server without restarting it, so applications should be able to handle the connection pool properly on their own.
Thanks again
Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
I found this link:
He had the same problem, and fixed it using dbcp as the connection pool. So I downloaded it and configured the hibernate.cfg.xml as he did, but nothing happened. He says that hibernate will use dbcp simply adding a dbcp configuration property to the hibernate.cfg.xml. Well, I copied his config and this is what I get from hibernate:

As you can see it's still using hibernate's default connection pool. Am I missing something?
Thanks a lot.
It is sorta covered in the JavaRanch Style Guide.
subject: c3p0 configuration
Similar Threads
Connection pooling using hibernate and struts1.3
Problems to connect to mysql with hibernate
com.mysql.jdbc.CommunicationsException MESSAGE: Communications link failure due to underlying except
Hibernate and MySQL connection issues
Hibernate, MySQL and the EOFException