本文介绍了休眠> 3.3和c3p0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于c3p0似乎不再与Hibernate捆绑在一起(因为版本> 3.3,我使用的是Hibernate 3.6.0),所以我想知道如何将c3p0与Hibernate集成。



很明显,旧方法中有

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

似乎不再起作用,因为Hibernate不再提供C3P0ConnectionProvider类。我现在必须自行构建它,还是安全地集成hibernate-c3p0-3.3.x.jar?

注意:我正在使用裸Hibernate,没有Spring等。

解决方案

我在 hibernate.cfg.xml中使用以下内容

 <! -  c3p0 config http://www.hibernate.org/214.html  - > ; 
< property name =connection.provider_class> org.hibernate.connection.C3P0ConnectionProvider< / property>
< property name =hibernate.c3p0.acquire_increment> 1< / property>
< property name =hibernate.c3p0.idle_test_period> 60< / property>
< property name =hibernate.c3p0.min_size> 1< / property>
< property name =hibernate.c3p0.max_size> 2< / property>
< property name =hibernate.c3p0.max_statements> 50< / property>
< property name =hibernate.c3p0.timeout> 0< / property>
< property name =hibernate.c3p0.acquireRetryAttempts> 1< / property>
< property name =hibernate.c3p0.acquireRetryDelay> 250< / property>

我使用最新的hibernate(目前为3.6.0 GA),并且包含在classpath c3p0-0.9.1.2.jar (当前最新)。一切都按预期工作。


As c3p0 does not seem to be bundled with Hibernate anymore (as of versions > 3.3, I am using Hibernate 3.6.0), I'd like to know how to integrate c3p0 with Hibernate.

Obviously the old approach with

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

does not seem to work anymore, as the class C3P0ConnectionProvider is not provided by Hibernate anymore. Do I now have to build this on my own or is it safe to integrate the hibernate-c3p0-3.3.x.jar?

Note: I am using bare Hibernate, no Spring etc.

解决方案

I use the following in hibernate.cfg.xml:

<!-- c3p0 config http://www.hibernate.org/214.html -->
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">60</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">2</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.timeout">0</property>
<property name="hibernate.c3p0.acquireRetryAttempts">1</property>
<property name="hibernate.c3p0.acquireRetryDelay">250</property>

I use the latest hibernate (currently 3.6.0 GA) and I've included in the classpath c3p0-0.9.1.2.jar (currently latest). Everything works as expected.

这篇关于休眠&gt; 3.3和c3p0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:23