Hibernate,C3P0,Mysql - Broken Pipe [英] Hibernate, C3P0, Mysql -- Broken Pipe
问题描述
我已经查看了代码,并确认我犯了或回滚所有事务。
这是我的hibernate.cfg.xml
<?xml version =1.0encoding =utf-8?>
<!DOCTYPE hibernate-configuration PUBLIC - // Hibernate / Hibernate Configuration DTD 3.0 // ENhttp://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd\">
< hibernate-configuration>
< session-factory>
< property name =hibernate.bytecode.use_reflection_optimizer> false< / property>
< property name =hibernate.connection.driver_class> org.gjt.mm.mysql.Driver< / property>
< property name =hibernate.connection.password>< / property>
< property name =hibernate.connection.url> jdbc:mysql:// localhost / test< / property>
< property name =hibernate.connection.username>根< / property>
< property name =hibernate.dialect> org.hibernate.dialect.MySQL5InnoDBDialect< / property>
< property name =hibernate.transaction.factory_class> org.hibernate.transaction.JDBCTransactionFactory< / property>
< property name =hibernate.current_session_context_class>线程< / property>
<! - property name =hibernate.show_sql> true< / property>
< property name =hibernate.format_sql> true< / property - >
< property name =c3p0.min_size> 3< / property>
< property name =c3p0.max_size> 5< / property>
< property name =c3p0.timeout> 1800< / property>
< property name =c3p0.preferredTestQuery> SELECT 1< / property>
< property name =c3p0.testConnectionOnCheckout> true< / property>
< property name =c3p0.idle_test_period> 100< / property> <! - 秒 - >
< property name =cache.provider_class> org.hibernate.cache.NoCacheProvider< / property>
< property name =cache.use_query_cache> false< / property>
< property name =cache.use_minimal_puts> false< / property>
< property name =max_fetch_depth> 10< / property>
< property name =hibernate.hbm2ddl.auto>更新< / property>
<! - - 课程已移除 - >
< / session-factory>
我认为参数修正它是 c3p0.idle_test_period
- 它默认为0.但是,我们在运行8小时后仍然存在Broken Pipe问题。虽然有多个帖子通过谷歌索引,但没有一个满意的答案。
hibernate.c3p0.max_size
属性启用了c3p0连接池。但是,在3.x中,您必须指定以下属性 - < property name =hibernate.connection.provider_class > org.hibernate.connection.C3P0ConnectionProvider< /性>
另外,这里是我的最终配置参数 -
< property name =hibernate.c3p0.min_size> 3< / property>
< property name =hibernate.c3p0.max_size> 5< / property>
< property name =hibernate.c3p0.timeout> 1800< / property>
< property name =hibernate.c3p0.idle_test_period> 100< / property> <! - 秒 - >
很遗憾,Hibernate和c3p0在这方面的记录都很糟糕。
MySQL seems to have an 8 hour time out on its connections. I'm running multiple WARs in Tomcat utilizing Hibernate for ORM. After 8 hours (i.e. overnight), I get broken pipes when it picks up an idle connection.
I've already traced through the code and made doubly sure I commit or rollback all transactions.
Here is my hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<!--property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property-->
<property name="c3p0.min_size">3</property>
<property name="c3p0.max_size">5</property>
<property name="c3p0.timeout">1800</property>
<property name="c3p0.preferredTestQuery">SELECT 1</property>
<property name="c3p0.testConnectionOnCheckout">true</property>
<property name="c3p0.idle_test_period">100</property> <!-- seconds -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="cache.use_query_cache">false</property>
<property name="cache.use_minimal_puts">false</property>
<property name="max_fetch_depth">10</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- classes removed -->
</session-factory>
The parameter I thought would have fixed it was the c3p0.idle_test_period
-- It defaults to 0. However, we still have the Broken Pipe issue after 8 hours of running. While there are multiple posts index via Google, none arrive at a satisfactory answer.
So it turns out I was missing a key line that enabled c3p0 (the c3p0 parameters I was tweaking were having no effect because Hibernate was using it's built in connection pool -- which it appropriately warns is not suitable for production). In hibernate 2.x, setting the hibernate.c3p0.max_size
property enabled c3p0 connection pooling. However, in 3.x you must specify the following property --
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
Additionally, here are my final configuration parameters --
<property name="hibernate.c3p0.min_size">3</property>
<property name="hibernate.c3p0.max_size">5</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.idle_test_period">100</property> <!-- seconds -->
It's rather unfortunate that both Hibernate and c3p0 have abysmal documentation in this regard.
这篇关于Hibernate,C3P0,Mysql - Broken Pipe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!