如何在hibernate中配置c3p0以自动刷新过时的数据库连接 [英] How to configure c3p0 in hibernate to auto-refresh stale DB connections
问题描述
我在我的应用程序中使用hibernate 3,c3p0 9.1.2,Oracle 11g。如果我重新启动Oracle,那么过时的连接不会得到刷新,并且我收到异常java.sql.SQLRecoverableException:Closed Connection。以下是我的hibernate.cfg.xml。
我是Hibernate API的初学者。你能建议如何配置hibernate在指定的时间自动刷新陈旧的连接。
这是我的hibernate.cfg.xml
oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin :@localhost:1521:ems
emsman
< property name =hibernate.c3p0.idle_test_period> 60℃/性> <! - 秒 - >
< property name =hibernate.c3p0.min_size> 5< / property>
< property name =hibernate.c3p0.max_size> 20< / property>
< property name =hibernate.c3p0.timeout> 1800< / property>
< property name =hibernate.c3p0.max_statements> 50< / property>
< property name =show_sql> false< / property>
< property name =dialect> org.hibernate.dialect.OracleDialect< / property>
< property name =c3p0.validate> true< / property>
< mapping resource =< package-name> /GroupOpWorkflow.hbm.xml/>
< mapping resource =< package-name> /GroupOperation.hbm.xml/>
< mapping resource =< package-name> /GroupOpNode.hbm.xml/>
< mapping resource =< package-name> /NodeStatusLog.hbm.xml/>
< / session-factory>
它是 c3p0
,您的数据库连接池,您需要配置 - 而不是休眠。尝试设置 idleConnectionTestPeriod
和合适的 preferredTestQuery
,例如从双$ c中选择1 $ C>。
validate
属性已被弃用,建议您不要使用它。
请参阅 http://community.jboss.org / wiki / HowToConfigureTheC3P0ConnectionPool 了解更多信息。如果您在 WEB-INF / classes
中创建 c3p0.properties
文件,但您需要最多的控制权确保不要覆盖 hibernate.cfg.xml
中的那些属性。
I am using hibernate 3, c3p0 9.1.2, Oracle 11g in my application. If I restart the Oracle then the stale connections are not getting refresh and I am getting exception "java.sql.SQLRecoverableException: Closed Connection". Below is my hibernate.cfg.xml.
I am a beginner in Hibernate API. Can you please suggest how to configure hibernate to automatically refresh the stale connections on a specified time.
Here is my hibernate.cfg.xml
oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@localhost:1521:ems emsman
<property name="hibernate.c3p0.idle_test_period">60</property> <!-- seconds -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="show_sql">false</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="c3p0.validate">true</property>
<mapping resource="<package-name>/GroupOpWorkflow.hbm.xml"/>
<mapping resource="<package-name>/GroupOperation.hbm.xml"/>
<mapping resource="<package-name>/GroupOpNode.hbm.xml"/>
<mapping resource="<package-name>/NodeStatusLog.hbm.xml"/>
</session-factory>
It's c3p0
, your database connection pool, that you need to configure - not hibernate. Try setting idleConnectionTestPeriod
and an appropriate preferredTestQuery
, e.g., select 1 from dual
. The validate
property has been deprecated and it's recommended that you not use that.
See http://community.jboss.org/wiki/HowToConfigureTheC3P0ConnectionPool 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
.
这篇关于如何在hibernate中配置c3p0以自动刷新过时的数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!