-->
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.  [ 1 post ] 
Author Message
 Post subject: mysql+hibernte 'autoReconnect=true' to avoid this connection
PostPosted: Wed Jun 05, 2013 3:55 am 
Newbie

Joined: Wed Jun 05, 2013 3:41 am
Posts: 1
I deploy application in the night. Test the application & everything works properly. In the morning when client try that application, he receive error. When I check log, error was

Code:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 34,431,201 milliseconds ago.  The last packet sent successfully fully to the server was 34,431,201 milliseconds ago. 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 to avoid this problem.


After googling, I understood that mysql close the inactive connection after certain period (default = 8 hrs) & when hibernate try to communicate with database, the connections are close. And thats why this error come. But I am stuck with this problem & I didnt find solution that works for me.

Here is my configuration

Code:
 
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <!--
        From MySQL document -
         Should the driver try to re-establish stale and/or dead connections? If enabled the driver will throw an
         exception for a queries issued on a stale or dead connection, which belong to the current transaction, but will
         attempt reconnect before the next query issued on the connection in a new transaction. <b>The use of this
         feature is not recommended, because it has side effects related to session state and data consistency when
         applications don't handle SQLExceptions properly </b>
         http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html
         -->
        <property name="url" value="jdbc:mysql://localhost:3306/mydb"/>
        <property name="username" value="username"/>
        <property name="password" value="password"/>

    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.channel.model"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
                <prop key="hibernate.current_session_context_class">thread</prop>
                <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.query.substitutions">true 'T', false 'F'</prop>

                <prop key="c3p0.min_size">5</prop>
                <prop key="c3p0.max_size">20</prop>
                <prop key="c3p0.timeout">1800</prop>
                <prop key="c3p0.max_statements">50</prop>
                <prop key="hibernate.c3p0.preferredTestQuery">SELECT 1 FROM DUAL;</prop>
                <prop key="hibernate.c3p0.testConnectionOnCheckout">true</prop>
                <prop key="hibernate.c3p0.validate">true</prop>
                <prop key="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
            </props>
        </property>
    </bean>





Can you please suggest the proper configuration.


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

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.