Connection with the Bank falls after a certain time


I have a server where I have several web applications connected to the database ( Mysql ). The problem is that if some system is idle it loses the connection with the bank and I have to give a refresh in the application so that everything returns to normal.

I was circumventing this problem with a Thread pinging the database every 1 hour. But now that I'm working with WEBServices this method is no longer working.

I have read in some places that Mysql overturns all connections if idle for 8 hours. And I also found several possible solutions, such as configuring C3P0 , etc. But even making these settings the error still persists. In the Log of Tomcat I have these errors:

Caused by: org.hibernate.TransactionException: commit failed
Caused by: org.hibernate.TransactionException: unable to commit against JDBC connection
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
Caused by: Software caused connection abort: socket write error

I'm using Hibernate , and my settings look like this:

<!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/bd</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>
        <property name="connection.autoReconnect">true</property>
        <property name="connection.autoReconnectForPools">true</property>

        <!-- C3P0 -->
        <property name="c3p0.acquire_increment">5</property>
        <property name="c3p0.timeout">0</property>
        <property name="c3p0.min_size">3</property>
        <property name="c3p0.max_size">100</property>
        <property name="c3p0.max_statements">0</property>
        <property name="c3p0.idle_test_period">3000</property>

I put timeout to 0 because in some places they say that the connection never expires, but it continues to expire.

Is my setup right? Do I need to do any other configuration? Is there another way to solve this problem?


I noticed that even with these errors I can still add, change and edit the data, but whenever I try to perform one of these operations, I have a

asked by anonymous 18.12.2015 / 14:30

2 answers


There are several things to try to test, I'll put some.

On the connection line you can try to put the autoReconnect argument

<property name="connection.url">jdbc:mysql://localhost:3306/bd?autoReconnect=true</property>

Also add a provider for C3P0

<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>  

And finally, the property to test the connection in a checkout.

Create a file, or if you are already using the c3p0-config.xml add the property as true link


A second alternative

Find the file my.ini or my.cnf in the mysql directory for your operating system , in that link there are examples of paths where the directory is located.

If you do not find it initially, also check that the file is not hidden . In either case it works.

When found, add the following lines to the values, which are recognized in seconds

wait_timeout = 99999999999999999999999 
interactive_timeout = 99999999999999999999999

By default, these even if implicit values are 8 horas , or 28800 segundos .

23.12.2015 / 15:08

Take a look at the settings of this other post, I believe your problem will be solved.

Consider the idleConnectionTestPeriod and maxIdleTimeExcessConnections

Best configuration of c3p0 [closed]

23.12.2015 / 14:35