I have been having trouble with Hibernate and Mysql timeout error.I am also using properties of c3p0(connection provider). After my Hibernate/MySQL have been running after 8 hours(which is default timeout value in Mysql), I have the exception. But it doesn't help.
property for auto reconnect also not working.
Here is my Hibernate Configuration:
<property name="connection_provider_class">org.hibernate.connection.C3P0ConnectionProvider</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.validate">true</property>
<property name="current_session_context_class">thread</property>
<property name="cache.use_query_cache">false</property>
<property name="cache.use_second_level_cache">false</property>
<property name="c3p0.idle_test_period">20</property>
<property name="c3p0.timeout">40</property>
<property name="c3p0.max_size">100</property>
<property name="c3p0.min_size">1</property>
<property name="c3p0.acquireRetryAttempts">10</property>
<property name="c3p0.maxPoolSize">100</property>
<property name="c3p0.maxIdleTime">300</property>
<property name="c3p0.maxStatements">50</property>
<property name="c3p0.minPoolSize">10</property>
<property name="c3p0.preferredTestQuery">select 1;</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/doqeap</property>
<property name="connection.user">root</property>
<property name="connection.password">*******</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.jdbc.batch_size">0</property>
<mapping></mapping>
please help me to sort out this problem.
Thanks
If the Connection timeout is the issue, then Connection testing should eliminate, wither via tests on checkout (reliable but imposes a client visible performance cost) or tests on checking + idle tests.
Looking at you config params, it looks like you mean to set tests on checkouts and idle tests. I'd expect that c3p0 would eliminate timed out Exceptions before your app saw them. If that hasn't happened, it'd be interesting to see two things: 1) c3p0's config, which gets logged at INFO when the pool is initialized -- is c3p0, through the hibernate layer, seeing the configuration you intend? 2) the Exception that your app receives when it encounters the stale Connections.
Good luck!
Related
After (early all works ok) setting c3p0 connection pool to PostgreSQL DB like this:
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">500</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
can't realize PUT (only) requests. Hibernate works ok, but there are no records in DB. I tried different sets without result. What's wrong?
UPD: as we see in DB: PUT requests comes (they correct) but Hibernate rollback them. Why?
Find solution:
<property name="hibernate.c3p0.autoCommitOnClose">true</property>
It's works. But i'am not sure in it correction.
I use spring jdbc template for app.. and deploy it in tomcat.. I want to use connection pool with tomcat jdbc. My connection configuration is
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3310/mydb" />
<property name="username" value="***" />
<property name="password" value="***" />
<property name="maxWait" value="10000" />
<property name="removeAbandonedTimeout" value="60" />
<property name="removeAbandoned" value="true" />
<property name="logAbandoned" value="false" />
<property name="initialSize" value="10" />
<property name="maxActive" value="100" />
<property name="minIdle" value="10" />
</bean>
I don't know how, but when I run some test, and check the max thread in mysql, it show that the active thread is more than the maxActive configured in the configuration. So, why the maxActive in the configuration not working? And how to make it work? For example, the maxActive is 100 but when I check in mysql, the active thread is more than the maxActive.
maxActive (int) The maximum number of active connections that can be
allocated from this pool at the same time. The default value is 100
maxIdle (int) The maximum number of connections that should be kept in
the pool at all times. Default value is maxActive:100 Idle connections
are checked periodically (if enabled) and connections that been idle
for longer than minEvictableIdleTimeMillis will be released. (also see
testWhileIdle)
So i should recommend you to use maxIdle too, example:
<property name="maxIdle" value="100">
But maybe there is a problem, if you could show the code of your connection management, it would be helpful.
Here is an interesting link of a connection problem with declarative and programmatic transaction management with Spring: Connection pool problem with Spring and programmatic transaction management
I got the same problem with you and my tomcat version is tomcat 9.
Here is my solution: you should set maxTotal value 100 instead of maxActive.
maxTotal: Maximum number of database connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to -1 for no limit.
FROM http://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html.
My application has a timer that execute every 60 seconds. Each execution will access the oracle database with C3p0 connection pool. The existing configuration for C3p0 of my application is as following(there are other tasks to access db):
*<property name="acquireIncrement" value="1"/>
<property name="initialPoolSize" value="10"/>
<property name="maxPoolSize" value="25"/>
<property name="minPoolSize" value="10"/>
<property name="maxStatements" value="250"/>
<property name="maxStatementsPerConnection" value="10"/>
<property name="numHelperThreads" value="6"/>
<property name="checkoutTimeout" value="30000"/>
<property name="maxIdleTimeExcessConnections" value="1800"/>
<property name="idleConnectionTestPeriod" value="900"/>
<property name="preferredTestQuery" value="SELECT 'x' FROM DUAL"/>*
Now I got an issue that when database shutdown, the timer will throw SQLexcetion for bad connection for each execution, but when the database recover, it keep throwing SQLExcetion for bad connection.
I think that the reason should be when application startup, 10 connection will be established, and timer occupy one of them, when database shutdown, the connection broken, and then database recover, the timer still uses the broken connection.
But I am not sure whether my assumption is correct, the timer will use single connection for its each execution even it has already broken?
If my thinking is correct, I want to reduce idleConnectionTestPeriod to less than 60 seconds that is the time intenal of timer to fix this issue.
Could you guide me on this problem? Thank you.
Hello everyone,
I am using hibernate ORM and oracle database. My cfg file has following properties:
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:#url</property>
<property name="connection.username">username</property>
<property name="connection.password">pasword</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">3</property>
Everything works fine, but when I run the application and if I unplug network cable and plug it agian my db queries fail. It gives me the error
java.sql.SQLException: Io exception: Connection reset by peer: socket write error
Is there any way to re establish the connection?
You need to configure your database connection pool - not hibernate.Try setting idleConnectionTestPeriod and an appropriate preferredTestQuery, e.g., select 1 from dual.
See How To Configure The C3P0 ConnectionPool for more information. You'll get the most control if you create a c3p0.properties file in WEB-INF/classes but you need to make sure not to override those properties in your hibernate.cfg.xml.
Well I had written c3p0-config.xml like
<c3p0-config>
<default-config>
<!-- Configuring Connection Testing -->
<!-- property name="automaticTestTable">TEST_EMS_HIBERNATE_CONN</property -->
<property name="checkoutTimeout">0</property>
<property name="testConnectionOnCheckout">true</property>
<property name="testConnectionOnCheckin">false</property>
<property name="preferredTestQuery">SELECT 1 from dual</property>
<!-- Configuring Recovery From Database Outages -->
<property name="acquireRetryAttempts">0</property>
<property name="acquireRetryDelay">1000</property>
<property name="breakAfterAcquireFailure">false</property>
<!-- Configuring to Debug and Workaround Broken Client Apps -->
<property name="unreturnedConnectionTimeout">1800</property>
<property name="debugUnreturnedConnectionStackTraces">true</property>
</default-config>
and the system properties like:
C3P0_SYS_PROPS="-Dcom.mchange.v2.c3p0.cfg.xml=<FILE-PATH>/c3p0-config.xml -Dcom.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog -Dcom.mchange.v2.log.FallbackMLog.DE
FAULT_CUTOFF_LEVEL=WARNING"
As I see, you have specified when test connection, but have not specified how to test them. Read it http://www.mchange.com/projects/c3p0/index.html#configuring_connection_testing . I guess you should just add preferredTestQuery, usually it's something like SELECT 1 FROM DUAL.
Also read here Something wrong with Hibernate DB connection pooler c3p0
I develop an applivation with very load(request).
I used following technologies in my appliation:
Jpa/Hibernate as persistense layer
Spring and Spring Dao
C3p0 as connection pooling
my problem is : I run my application , when number of request increase, throw exception in
persistense layer that"Cannt open connection"
I increase oracle max session but my problem not solve
I indept in C3p0 document and test its options but my problem not solve.
Thank you for your attention
You increased max sessions on Oracle, but you didn't increase the max size of your connection pool. The exception is telling you that your pool is exhausted. Either find what's holding connections open and get them released sooner, or increase the number of max active connections in the pool.
Is it possible for you to post the Spring configuration for your DataSource. I would expect something like:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
<property name="jdbcUrl" value="${jdbc.connection.url}"/>
<property name="user" value="${jdbc.connection.username}"/>
<property name="password" value="${jdbc.connection.password}"/>
<property name="initialPoolSize" value="5"/>
<property name="minPoolSize" value="5"/>
<property name="maxPoolSize" value="100"/>
</bean>
With another bean configured where the dataSource is passed by reference:
<bean id="mySampleDao" class="com.example.dao.MySampleDao">
<property name="dataSource" ref="dataSource" />
</bean>
Is this what you have?
What version of Oracle are you using?