-->
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: ERROR org.hibernate.util.JDBCExceptionReporter
PostPosted: Mon Sep 29, 2008 1:28 am 
Newbie

Joined: Sun Sep 28, 2008 5:28 am
Posts: 4
HI guys,
I'm new in hibernate.
For last one month i was getting exception when i'm trying to call a scheduler from a servlet.I was getting this exception every 2nd or 3rd day from the server restart..Then when i again restarted my apps server(RESIN 3.1) the scheduler worked fine for two days and in third day i got this exception.

Code:
com.mchange.v2.c3p0.stmt.GooGooStatementCache - Problem with checked-in Statement, discarding.
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: No operations allowed after statement closed.


Then i resolved this exception by
1.writing session.close() in finally block in the DAO.
2.Using the latest mysql connector
3.setting this<property name="hibernate.c3p0.timeout">18000</property> and
<property name="c3p0.max_statements">0</property>
etc etc..This forrum helped me a lot in understanding and using these configurations.


but now i'm getting this new ERROR every two days .Now i have to again restart my server whenever i get exception.ie
Code:
WARN  org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 08S01

Code:
ERROR org.hibernate.util.JDBCExceptionReporter - The last packet successfully received from the server was86384 seconds ago.The last packet sent successfully to the server was 86384 seconds ago, which  is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem


can you help me out in figuring where i'm going wrong and helping me to resolve this.

Hibernate version:3.0

Mapping documents:
Code:
<session-factory>
   <!-- properties -->
   <property name="connection.username">test</property>
   <property name="connection.url">jdbc:mysql://10.1.10.31/airtel_test?autoReconnect=true</property>
   <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
   <property name="connection.password">test</property>
   <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

   <property name="connection.autoReconnect">true</property>
   <property name="connection.autoReconnectForPools">true</property>
   <property name="connection.is-connection-validation-required">true</property>

   <!--  <property name="c3p0.max_size">100</property>
   <property name="c3p0.min_size">10</property>
   <property name="c3p0.timeout">0</property>
   <property name="c3p0.max_statements">50</property>
    <property name="c3p0.acquire_increment">1</property>
   <property name="c3p0.idle_test_period">10</property>

   <property name="hibernate.c3p0.idleConnectionTestPeriod">300</property>
     <property name="hibernate.c3p0.minPoolSize">10</property>
   <property name="hibernate.c3p0.maxPoolSize">100</property>
   <property name="hibernate.c3p0.maxConnectionAge">14400</property>-->



   <!-- new configuration for c3p0 version 0.9.1.2-->
   <property name="hibernate.c3p0.preferredTestQuery">select 1;</property>
   <property name="c3p0.testConnectionOnCheckout">true</property>
   <!-- Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 0
   If this is a number greater than 0, c3p0 will test all idle, pooled but unchecked-out connections, every this number of seconds -->
   <property name="c3p0.acquire_increment">1</property>
   <!-- Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 0
   If this is a number greater than 0, c3p0 will test all idle, pooled but unchecked-out connections, every this number of seconds -->
   <property name="c3p0.idle_test_period">10</property>
   <property name="c3p0.initialPoolSize">3</property><!-- initialPoolSize C3P0 default: 3 -->
   <property name="c3p0.maxIdleTime">18000</property><!-- don't know the value -->
   <!-- maxPoolSize Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 100 -->
   <property name="c3p0.maxPoolSize">100</property>
   <!-- maxStatements Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 0
   The size of c3p0's PreparedStatement cache. Zero means statement caching is turned off. -->
   <property name="c3p0.max_statements">0</property>

   <!-- minPoolSize Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 1 -->
   <property name="c3p0.minPoolSize">10</property>
   <!-- testConnectionOnCheckout Must be set in c3p0.properties, C3P0 default: false
   Don't use it, this feature is very expensive. If set to true, an operation will be performed at every
   connection checkout to verify that the connection is valid. A better choice is to verify connections
   periodically using c3p0.idleConnectionTestPeriod. -->
   <property name="c3p0.testConnectionsOnCheckout">true</property>




   <!-- acquireIncrement Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 1
   Determines how many connections at a time c3p0 will try to acquire when the pool is exhausted. -->
   <property name="hibernate.c3p0.acquire_increment">1</property>

   <!-- Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 0
   If this is a number greater than 0, c3p0 will test all idle, pooled but unchecked-out connections, every this number of seconds -->
   <property name="hibernate.c3p0.idle_test_period">10</property>

   <!-- timeout Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 0
   The seconds a Connection can remain pooled but unused before being discarded. Zero means idle connections never expire. -->
   <property name="hibernate.c3p0.timeout">18000</property>

   <!-- maxPoolSize Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 100 -->
   <property name="hibernate.c3p0.max_size">100</property>

   <!-- maxStatements Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 0
   The size of c3p0's PreparedStatement cache. Zero means statement caching is turned off. -->
   <property name="hibernate.c3p0.max_statements">0</property>
   <!-- minPoolSize Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 1 -->
   <property name="hibernate.c3p0.min_size">10</property>

   <property name="hibernate.show_sql">false</property>



Code between sessionFactory.openSession() and session.close():
Code:
package com.hibernate;

import org.hibernate.HibernateException;
import org.hibernate.Session;
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 SessionFactory {

    /**
     * Location of hibernate.cfg.xml file.
     * NOTICE: Location should be on the classpath as Hibernate uses
     * #resourceAsStream style lookup for its configuration file. That
     * is place the config file in a Java package - the default location
     * is the default Java package.<br><br>
     * Examples: <br>
     * <code>CONFIG_FILE_LOCATION = "/hibernate.conf.xml".
     * CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml".</code>
     */
    private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";

    /** Holds a single instance of Session */
    private static final ThreadLocal threadLocal = new ThreadLocal();

    /** The single instance of hibernate configuration */
    private static final Configuration cfg = new Configuration();

    /** The single instance of hibernate SessionFactory */
    private static org.hibernate.SessionFactory sessionFactory;

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

        if (session == null || session.isOpen() == false) {
            if (sessionFactory == null) {
                try {
                    cfg.configure(CONFIG_FILE_LOCATION);
                    sessionFactory = cfg.buildSessionFactory();
                }
                catch (Exception e) {



                    System.err.println("%%%% Error Creating SessionFactory %%%%");
                    e.printStackTrace();
                }
            }
            session = sessionFactory.openSession();
            threadLocal.set(session);
        }

        return session;
    }

    /**
     *  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();
        }
    }

    /**
     * Default constructor.
     */
    private SessionFactory() {
    }

}



Full stack trace of any exception that occurs:
WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 08S01
ERROR org.hibernate.util.JDBCExceptionReporter - The last packet successfully received from the server was86384 seconds ago.The last packet sent successfully to the server was 86384 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.


Name and version of the database you are using:5.0.45-community-log MySQL Community Edition (GPL)


mysql default wait_timeout=28800..











[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 12:41 am 
Newbie

Joined: Sun Sep 28, 2008 5:28 am
Posts: 4
can anyone of you help me in resolving this.[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2008 9:42 am 
Newbie

Joined: Mon Nov 03, 2008 9:40 am
Posts: 2
I solved it like this:

http://www.databasesandlife.com/automat ... -to-mysql/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2008 4:17 am 
Newbie

Joined: Sun Sep 28, 2008 5:28 am
Posts: 4
Thanks for your reply and the url provided by you was helpful..But i have something more to say...
i'm using c3p0 and configuring it in hibernate-cfg.xml itself.

<property name="c3p0.testConnectionOnCheckout">true</property> ...But still i'm getting the same exception

ERROR org.hibernate.util.JDBCExceptionReporter - The last packet successfully received from the server was86384 seconds ago.The last packet sent successfully to the server was 86384 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

You are lucky that your problem is resolved.
I doubt about three things..ie
<property name="hibernate.c3p0.timeout">18000</property>
<property name="c3p0.maxIdleTime">18000</property>
<property name="c3p0.testConnectionOnCheckout">true</property> .....is this property available to c3p0...[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2008 6:35 am 
Newbie

Joined: Mon Nov 03, 2008 9:40 am
Posts: 2
You can't configure the "testConnectionOnCheckout" using the hibernate-cfg.xml, unfortunately. You have to create the "c3p0.properties" file and put it in the root of the classpath. This wasn't too convenient for me, but it's what worked...


Top
 Profile  
 
 Post subject: Re:
PostPosted: Mon May 09, 2011 12:49 pm 
Newbie

Joined: Thu May 05, 2011 3:31 am
Posts: 8
AdrianSmith wrote:
You can't configure the "testConnectionOnCheckout" using the hibernate-cfg.xml, unfortunately. You have to create the "c3p0.properties" file and put it in the root of the classpath. This wasn't too convenient for me, but it's what worked...


hello,
I followed your solution and added c3p0 properties file ... and with server starts
I can see that the configration in ok in logs :
Quote:
[5/6/11 08:08:35:728 BST] [INFO] - Initializing c3p0-0.9.1.1 [built 15-March-2007 01:32:31; debug? true; trace: 10]
[5/6/11 08:08:36:389 BST] [INFO] - Hibernate Annotations 3.4.0.GA
[5/6/11 08:08:38:378 BST] [INFO] - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> ugpgr88f1if5iimju67k5|5b891, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> ugpgr88f1if5iimju67k5|5b891, idleConnectionTestPeriod -> 300, initialPoolSize -> 5, jdbcUrl -> jdbc:mysql://localhost:3306/amsac_emr, lastAcquisitionFailureDefaultUser -> null, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 3600, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> select 1;, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> true, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]


but as the conection goes stale it donot validates or removes from pool... I am stucked ...


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.