aspose file tools*
The moose likes Object Relational Mapping and the fly likes communication link failure revised Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "communication link failure revised" Watch "communication link failure revised" New topic
Author

communication link failure revised

Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
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

2007-01-08 22:53:40,793 [ TP-Processor2] WARN com.hms.action.WelcomeAction.execute(WelcomeAction.java:49) - Archive path :/usr/local/archive
now creating transaction
2007-01-08 22:53:49,105 [ TP-Processor4] WARN org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:71) - SQL Error: 0, SQLState: 08S01
2007-01-08 22:53:49,106 [ TP-Processor4] ERROR org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:72) - Communication link failure: java.io.EOFException, underlying cause: null

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

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.
*/

package com.hms.dao;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
* 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;

static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateUtil() {
}

/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();

if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
try{
System.out.println("now creating transaction");
final Transaction transaction = session.beginTransaction();
session.createSQLQuery("select 1").list();
transaction.commit();
System.out.println("after committing transx");
}catch(Exception e){
//check for sql state if 08S01 call get session again for 5 attempts
e.toString();
}


return session;
}

/**
* Rebuild hibernate session factory
*
*/
public synchronized static void rebuildSessionFactory() {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}

/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);

if (session != null) {
session.close();
}
}

/**
* return session factory
*
*/
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}

/**
* return session factory
*
* session factory will be rebuilded in the next call
*/
public static void setConfigFile(String configFile) {
HibernateUtil.configFile = configFile;
sessionFactory = null;
}

/**
* return hibernate configuration
*
*/
public static Configuration getConfiguration() {
return configuration;
}
}



Calling through error.jsp for testing
<%@ page import="com.hms.dao.HibernateUtil" %>


<%

org.hibernate.Session session = HibernateUtil.getSession();
HibernateUtil.closeSession();


%>
This is the error JSP page

Hibernate.cfg.xml file
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.username">ras13057_ras</property>
<property name="hibernate.connection.password">danira</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/ras13057_hms?autoReconnect=true
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<mapping resource="/User.hbm.xml"/>
<mapping resource="/Test.hbm.xml"/>
<mapping resource="/UserSubscription.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Maybe it is your connection pool settings, or connection settings where the JDBC connection timesout and loses connection.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
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
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
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

"i am not using connection pooling."

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
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
 
 
subject: communication link failure revised