码迷,mamicode.com
首页 > Web开发 > 详细

Hibernate4.3.8.Final在配置c3p0时,报错

时间:2015-04-19 21:12:37      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

Initial SessionFactory creation failed.org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]

在配置文件里的配置是这样的,
<!-- C3P0连接池设定-->
<!-- 使用c3p0连接池  配置连接池提供的供应商-->
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<!--在连接池中可用的数据库连接的最少数目 -->
<property name="c3p0.min_size">5</property>
<!--在连接池中所有数据库连接的最大数目  -->
<property name="c3p0.max_size">20</property>
<!--设定数据库连接的过期时间,以秒为单位,
如果连接池中的某个数据库连接处于空闲状态的时间超过了timeout时间,就会从连接池中清除 -->
<property name="c3p0.timeout">120</property>
<!--每3000秒检查所有连接池中的空闲连接 以秒为单位-->
<property name="c3p0.idle_test_period">3000</property>

注释掉这一行,错误没有了。
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

查看Hibernate4.3.8的手册,是这么表述的:

Hibernate‘s own connection pooling algorithm is, however, quite rudimentary. It is intended to help you get started and is not intended for use in a production system, or even for performance testing. You should use a third party pool for best performance and stability. Just replace thehibernate.connection.pool_size property with connection pool specific settings. This will turn off Hibernate‘s internal pool. For example, you might like to use c3p0.

C3P0 is an open source JDBC connection pool distributed along with Hibernate in the lib directory. Hibernate will use its org.hibernate.connection.C3P0ConnectionProvider for connection pooling if you sethibernate.c3p0.* properties. If you would like to use Proxool, refer to the packagedhibernate.properties and the Hibernate web site for more information.

hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
hibernate.connection.username = myuser
hibernate.connection.password = secret
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.PostgreSQL82Dialect

意思是,只需要将 

hibernate.connection.pool_size替换为

hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50

这几个属性就ok了,没有说配置 connection.provider_class这个属性。




Hibernate4.3.8.Final在配置c3p0时,报错

标签:

原文地址:http://www.cnblogs.com/homer3000/p/4439703.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!