Hi, i posted this topic b4 but looks like it became too complicated. So i created a simple jsp page and the issue is like if i leave my app idle for more than 10 minutes in throws up with this error. when i do refresh it works again. This error is reallly a problem and it happens only when i use hibernate. i have one more app on teh machine which uses normal jdbc approach and it works fine. Would anyone please give me any input on this The following are the details of stack trance and all the corresponidng file. bTW, i am using hte latest mysql j connected 5.x
java.io.EOFException at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1388) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1532) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1923) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1163) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1272) at com.mysql.jdbc.Connection.execSQL(Connection.java:2236) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1555) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139) at org.hibernate.loader.Loader.getResultSet(Loader.java:1669) at org.hibernate.loader.Loader.doQuery(Loader.java:662) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) at org.hibernate.loader.Loader.doList(Loader.java:2145) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029) at org.hibernate.loader.Loader.list(Loader.java:2024) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:111) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1655) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164) at com.hms.dao.HibernateUtil.getSession(HibernateUtil.java:71) at org.apache.jsp.jsp.error_jsp._jspService(org.apache.jsp.jsp.error_jsp:48) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) 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:213) 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:199) at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282) at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:754) at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:684) at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:876) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:595)
** END NESTED EXCEPTION **
MY HIBERNATEUTIL.java file
/* * HibernateUtil.java * * Created on December 7, 2006, 5:08 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */
/** * Configures and provides access to Hibernate sessions, tied to the * current thread of execution. Follows the Thread Local Session * pattern, see {@link http://hibernate.org/42.html }. */ public class HibernateUtil {
/** * Location of hibernate.cfg.xml file. * Location should be on the classpath as Hibernate uses * #resourceAsStream style lookup for its configuration file. * The default classpath location of the hibernate config file is * in the default package. Use #setConfigFile() to update * the location of the configuration file for the current session. */ private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml"; private static final ThreadLocal threadLocal = new ThreadLocal(); private static Configuration configuration = new Configuration(); private static org.hibernate.SessionFactory sessionFactory; private static String configFile = CONFIG_FILE_LOCATION;
/** * return session factory * * session factory will be rebuilded in the next call */ public static void setConfigFile(String configFile) { HibernateUtil.configFile = configFile; sessionFactory = null; }
Thanks. there is a wait_timeout parameter in mysql which can be set to a value. but the issue is even it is set to 2 hr or 8hr this error will again happen if the app is left idle for more than 8 hrs. i thought appending autoReconnect=true at the end of the database url should solve the issue but this is still going on. SOme people recommend me to catch the exception and again call the getSession method. Thats what i am proposing to do as the last solution. But want to try another easy method before that if someeone has any idea. Thansk Rashid
Rashid Darvesh
Ranch Hand
Joined: Feb 13, 2004
Posts: 189
posted
0
i checked with my web hosting company and they requested me to and they asked me to keep alive checks. what is this. is there any hibernate propety or i need to write down a progrma which keeps on pinging mysql. Pleaselet me know. i am not using connection pooling. BTW, upon his request i added teh new three lines in my hibernate.cfg.xml file <property name="connection.autoReconnect">true</property> <property name="connection.autoReconnectForPools">true</property> <property name="connection.is-connection-validation-required">true</property> any help Thanks Rashid
Doesn't Hibernate require you to have a Connection pool, either in managed envionemt like a datasource, or in unmanaged a connection pool implementation like C3PO?
Mark
Rashid Darvesh
Ranch Hand
Joined: Feb 13, 2004
Posts: 189
posted
0
Ok After 2 weeks of struggling and thorough testing i can claim now i got over this problem. As Mark said i started using DBCP connection pooling. i came acorss one thread where it told me that the default connection pooling hibernate uses is not good, i dont know how true was that user who told me if we configure just jdbc parameters in hibernate.cfg.xml then hibernate uses default connection pool build in hibernate and that is buggy. he asked me to use DBCP connection pool instead. The problem is that how uninformative stack trace is from hibernate. Anyway if anyone is struggling with this issue then i will happy to assist them and share the source code. Rashid
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.