hibernate problem

i have a hibernate problem , i am using hibernate to connect to the mysql database and i am using tomcat , when i restart my tomcat cat it works fine and database is connected , but after a while the connection is lost with the database and the following error is shown in the log file .

please tell me what to do ? .

net.sf.hibernate.exception.GenericJDBCException: Could not execute query

at net.sf.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:90)

at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:79)

at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)

at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4110)

at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1621)

at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:27)

at us.hpsoft.etools.utils.UserDatabaseHandler.getAllUserData(UserDatabaseHandler.java:1135)

at us.hpsoft.etools.action.RegistrationAction.login(RegistrationAction.java:62)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)

at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)

at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)

at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)

at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)

at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)

at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)

at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

at java.lang.Thread.run(Thread.java:595)

Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException

MESSAGE: Broken pipe

STACKTRACE:

java.net.SocketException: Broken pipe

at java.net.SocketOutputStream.socketWrite0(Native Method)

at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)

at java.net.SocketOutputStream.write(SocketOutputStream.java:136)

at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)

at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)

at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2689)

at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2618)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1551)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:930)

at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1024)

at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:88)

at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)

at net.sf.hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:868)

at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1618)

at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:27)

at us.hpsoft.etools.utils.UserDatabaseHandler.getAllUserData(UserDatabaseHandler.java:1135)

at us.hpsoft.etools.action.RegistrationAction.login(RegistrationAction.java:62)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)

at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)

at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)

at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)

at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)

at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)

at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)

at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

at java.lang.Thread.run(Thread.java:595)

** END NESTED EXCEPTION **

Last packet sent to the server was 1 ms ago.

at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2707)

at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2618)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1551)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:930)

at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1024)

at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:88)

at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)

at net.sf.hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:868)

at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1618)

... 30 more

[8266 byte] By [haroon123456a] at [2008-2-27]
# 1
Hi,I've encountered exactly the same problem with you. Did you find any solution? or anyone know how to solve the problem? URGENT! Please help! Thanks!lonlonbread
lonlonbreada at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 2
I just wanted to say we also have this exact problem. Anyone with any ideas on this?
skydiverxa at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 3
AFAIK this problem is related to broken mysql jdbc driver.mysql developers have refused to fix the problem, the only thing you can do is to use other database
Maris_Orbidansa at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 4
it also depends on JDBC pool implementation. mysql has this problem with SUN AS, too.Have you tried JBoss ?
Maris_Orbidansa at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 5
or Apache Geronimo ?
Maris_Orbidansa at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 6
you can also try to test all jdbc connections -as soon as you get a connection from pool try to execute some sql (SELECT CURDATE()) if this doesn't work then close it and grab a new connection.perhaps it will help
Maris_Orbidansa at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 7

Hi

I've modified hibernate.cfg.xml and add config for c3p0. It seems that the problem did not occur. You could try it by setting c3p0.idle_test_period=xx seconds.

Please let me know if it really help!! Thanks! =)

<!-- configuration pool via c3p0-->

<property name="c3p0.acquire_increment">1</property>

<property name="c3p0.idle_test_period">100</property> <!-- seconds -->

<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">100</property> <!-- seconds -->

<!-- DEPRECATED very expensive property name="c3p0.validate>-->

lonlonbread

lonlonbreada at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 8

Here is what I found after a day of searching which seems to solve this problem for me. My webhost failed to mention that they changed the following properties in MYSQL:

we allow 100 connections per user. Also we have connect_timeout=10, and wait_timeout=300. Please check if your Hibername aware about this.

The solution:

1) Download Commons DBCP and place the jar in the classpath.

2) Add the following lines to your hibernate.cfg.xml:

<property name="hibernate.dbcp.maxWait">300</property>

<property name="hibernate.dbcp.maxIdle">10</property>

<property name="hibernate.dbcp.maxActive">100</property>

I hope this helps someone and saves them some time...

-eckoice

eckoicea at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 9

The previous code actually gave me the same error. The following code works better:

<property name="c3p0.min_size">10</property>

<property name="c3p0.max_size">100</property>

<property name="c3p0.timeout">10</property>

<property name="c3p0.acquireRetryAttempts">30</property>

<property name="c3p0.acquireIncrement">5</property>

<property name="c3p0.idleConnectionTestPeriod">300</property>

<property name="c3p0.initialPoolSize">20</property>

<property name="c3p0.maxPoolSize">100</property>

<property name="c3p0.maxIdleTime">300</property>

<property name="c3p0.maxStatements">50</property>

<property name="c3p0.minPoolSize">10</property>

eckoicea at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 10
eckoice,You fixed my problem. Thanks!
KHestona at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 11

I am new to Hibernate and was experiencing the "broken pipe" problem. I followed your instructions and it cleared the connection problem. However I am getting this error.

org.hibernate.MappingException: Could not read mappings from resource: org/pukanala/mynews/RSSFeed.hbm.xml

The file is in the right place and the application was able to read it after I restart Tomcat. Did you encounter this problem?

Thanks in advance.

carli1a at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 12

Thanks for the solution, it helped us solve the similar broken pipe issue...But we suspect c3p0 to be consuminig lot of virtual memory(around 1.3 GB) on the linux box for our application that has java. mysql and hibernate. In addition we have used the log4j for logging , and we observed that c3p0 is generating extreme amount of logs that just shots up to log size to 23 MB. The configuration settings in hibernate.cfg.xml for c3p0 are:

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

<property name="c3p0.min_size">10</property>

<property name="c3p0.max_size">100</property>

<property name="c3p0.timeout">10</property>

<property name="c3p0.acquireRetryAttempts">30</property>

<property name="c3p0.acquireIncrement">5</property>

<property name="c3p0.idleConnectionTestPeriod">300</property>

<property name="c3p0.initialPoolSize">20</property>

<property name="c3p0.maxPoolSize">100</property>

<property name="c3p0.maxIdleTime">300</property>

<property name="c3p0.maxStatements">50</property>

<property name="c3p0.minPoolSize">10</property>

Any pointers would be appreciated.

Thanks

pooja2909a at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 13

Hi, I have the similar issue. I have tried the dbcp connection pool and no luck. I am now trying c3p0 option. I have question here...

1. How do we know whether Hibernate uses the c3p0 pooling ?

2. Do we need to copy some jars in a common/lib directory to get this into affect?

3. Which jar contains c3p0 APIs?

Any help would be greatly appreciated.

karikalan_78a at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...
# 14
Any particular reason for discussing non-AVK issues in this forum? There are plenty of good forums for Hibernate issues.
sahooa at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...