0

I am working on Spring+Hibernate+JSF but if i am ideal on a page for few minute i am getting exception when trying some Database query

 The last packet successfully received from the server was 2,615,049 milliseconds ago.  The last packet sent successfully to the server was 27 milliseconds ago.

Caused by: org.hibernate.TransactionException: JDBC begin transaction failed: 
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:76)
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
    at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1309)
    at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:474)
    ... 46 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Is this issue due to any configuration in my project or its database vendor issue in web.xml i made this entry

<session-config>
   <session-timeout>
          30
   </session-timeout>
 </session-config>

Connection pool

<bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUrl" value="jdbc:mysql://IP:3306/ccc" />
                <property name="user" value=" hariom" />
                <property name="password" value="password" />
        <property name="maxPoolSize" value="2" />
        <property name="maxStatements" value="0" />
        <property name="minPoolSize" value="1" />
</bean>
5
  • this question has been answered many times, search it Commented Jun 27, 2014 at 7:29
  • session-timeout setting is about http sessions and isn't related to database. To answer your question we should know more about your setup, especially about connection pool which you use. Is it Apache DBCP, c3p0, BoneCP or something else? How you configure datasource? Commented Jun 27, 2014 at 7:37
  • Added connection pool settings Commented Jun 27, 2014 at 7:42
  • Looks to me like the database server is closing the connection after X minutes of inactivity and the pool is not setup to deal with stale connections. Commented Jun 27, 2014 at 7:58
  • So what i have to do to resolve the issue? Commented Jun 27, 2014 at 9:23

1 Answer 1

1

You should add this property ;

<property name="validationQuery" value="SELECT 1" />

This will validate the connection ,and if mysql closed the connection your app won't try to send packet.

Sign up to request clarification or add additional context in comments.

7 Comments

But it should throw exception because if it closed it will not reconnect
your app understands the connections state with that validate query which is for mysql, and if required it will reconnect.
No other thing i have to change like pool size etc.
After adding above properties in my applicationcontext.xml file my application not working and not able to create the session
what is the exception ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.