-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: idle time
PostPosted: Wed Oct 31, 2007 6:00 am 
Newbie

Joined: Fri Jul 20, 2007 7:04 am
Posts: 6
Hi guys

Here's my problem, when i deploy my web applocation it on a server and leave it idle for a day (don't know sure the time), when a access it through a web browser i get the exception that follows bellow.

Thanks in advance.


Hibernate version: 3.2

Full stack trace of any exception that occurs:

Code:
java.lang.IllegalStateException
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1244)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at com.mysql.jdbc.CommunicationsException.<init>(CommunicationsException.java:180)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2723)
        at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:1401)
        at com.mysql.jdbc.Connection.realClose(Connection.java:4882)
        at com.mysql.jdbc.Connection.cleanup(Connection.java:2062)
        at com.mysql.jdbc.Connection.finalize(Connection.java:3369)
        at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
        at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
        at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
org.hibernate.TransactionException: JDBC commit failed
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:130)
        at com.commons.web.filters.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:43)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:595)
Caused by: com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:888)
        at com.mysql.jdbc.Connection.commit(Connection.java:2285)
        at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:139)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
        ... 13 more



Name and version of the database you are using: MySQL 5


My code:

Filter:

Code:
package com.commons.web.filters;

import com.commons.util.hibernate.HibernateUtil;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.hibernate.StaleObjectStateException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HibernateSessionRequestFilter implements Filter {

    private static Log fileLog = LogFactory.getFactory().getInstance(HibernateSessionRequestFilter.class);

    private SessionFactory sf;

    /**
    * Open a new Connection for any page request.
    * Any method that use hibernate, the filter gives him the same connection.
    * the method proccess the request, and the end when is done, he close the connection.
    */
    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain)
            throws IOException, ServletException {

        try {
            fileLog.debug("Starting a database transaction");
            sf.getCurrentSession().beginTransaction();

            // Call the next filter (continue request processing)
            chain.doFilter(request, response);

            // Commit and cleanup
            fileLog.debug("Committing the database transaction");
            sf.getCurrentSession().getTransaction().commit();

        }
        catch (StaleObjectStateException staleEx) {
            fileLog.error("This interceptor does not implement optimistic concurrency control!");
            fileLog.error("Your application will not work until you add compensation actions!");
            // Rollback, close everything, possibly compensate for any permanent changes
            // during the conversation, and finally restart business conversation. Maybe
            // give the user of the application a chance to merge some of his work with
            // fresh data... what you do here depends on your applications design.
            throw staleEx;
        }
        catch (Throwable ex) {
            // Rollback only
            ex.printStackTrace();
           
            fileLog.error(ex);
           
            try {
                if (sf.getCurrentSession().getTransaction().isActive()) {
                    fileLog.debug("Trying to rollback database transaction after exception");
                    sf.getCurrentSession().getTransaction().rollback();
                }
            }
            catch (Throwable rbEx) {
                fileLog.error("Could not rollback transaction after exception!", rbEx);
            }

            // Let others handle it... maybe another interceptor for exceptions?
            throw new ServletException(ex);
        }
    }

    public void init(FilterConfig filterConfig) throws ServletException {
        fileLog.debug("Initializing filter...");
        fileLog.debug("Obtaining SessionFactory from static HibernateUtil singleton");
        sf = HibernateUtil.getSessionFactory();
    }

    public void destroy() {}

}


Helper class:

Code:
public class HibernateUtil {

    /* static context */
   
    private static final SessionFactory sessionFactory;
    private static HibernateUtil hu;
   
    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
           
            throw new ExceptionInInitializerError(ex);
        }
    }
   
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
       
    public static HibernateUtil getInstance() {   
        return new HibernateUtil();
    }

    ...



Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 31, 2007 11:29 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Not sure but don't you think

"Caused by: com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown."


points to some kind of network failure?

_________________
Please rate this post if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 7:35 am 
Newbie

Joined: Fri Jul 20, 2007 7:04 am
Posts: 6
Don't think so, the network is fine, imo it's a problem with the connection with the mysql, or some pool problem when is gets idle or something like that.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 7:47 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
sure sounds like a spurious network failure, or some other failure at the database server.
If it's internal to your application it should be easy to reproduce it. If it's a network glitch it should be spurious or a one-off.

The error itself indicates that the data was written and a commit sent to the database, but the application never got a result back for that commit so it doesn't know if the commit succeeded.

That means that either the response from the database got lost in the network (hinting at a temporary network failure) or a timeout during the commit (which could potentially happen when committing extremely large transactions in a poorly configured database).

Of the two, the network is the usual suspect.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 12:09 pm 
Newbie

Joined: Fri Jul 20, 2007 7:04 am
Posts: 6
Ok i have been doing some testing and this has something to do with mysql timeout.

if i put this values on configuration file:

File: /etc/my.cnf
Option: wait_timeout = 60

I get the exception every 60 seconds, but this issues should be controled by hibernate connection pool?

What's the best way to resolv this?


Top
 Profile  
 
 Post subject: Re:
PostPosted: Thu Jun 13, 2013 1:02 pm 
Newbie

Joined: Thu Jun 13, 2013 12:57 pm
Posts: 1
[quote="ricardomarques"]Ok i have been doing some testing and this has something to do with mysql timeout.

if i put this values on configuration file:

File: /etc/my.cnf
Option: wait_timeout = 60

I get the exception every 60 seconds, but this issues should be controled by hibernate connection pool?

What's the best way to resolv this?[/quote]

ricarodomarques,
You could solve your problem? I am having the same problem would be grateful if you help me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.