Hibernate配置c3p0连接池

网上有很多Hibernate+c3p0配置方面的文章,不过大部分都是从Hibernate的文档里抄的,大概都是这样

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.PostgreSQLDialect

但是我照样配置之后,日志显示,使用的还是hibernate的内置的连接池,然后就上网查资料,jboss网站有一篇 [url=http://community.jboss.org/wiki/HowToconfiguretheC3P0connectionpool#comment-3485]HowTo configure the C3P0 connection pool[/url],里面讲的也还是配置这几项,下面有人回帖说如果想让hibernate3能正常使用c3p0,还需要一个hibernate-c3p0-3.x.x.-Final.jar,于是上网下载了这个文件,还是不行,而且仔细一看,这个jar里面就一个org.hibernate.connection.C3p0ConnectionProvider, hibernate3.jar里面已经包含有这个类了,根本就不需要这个额外的jar包。
后来又看了几个贴,还是不能解决问题,干脆直接去代码里找答案,在hibernate源代码里搜索c3p0,终于在org.hibernate.connection.ConnectionProviderFactory这个类的注释里看明白了,这个类的javadoc说“Instantiates a connection provider given either System properties or a java.util.Properties instance. The ConnectionProviderFactory first attempts to find a name of a ConnectionProvider subclass in the property hibernate.connection.provider_class. If missing, heuristics are used to choose either DriverManagerConnectionProvider, DatasourceConnectionProvider, C3P0ConnectionProvider or DBCPConnectionProvider.” 看来是要设置hibernate.connection.provider_class这个属性才行,在配置文件里加上
[color=red]hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider[/color]
再次运行,终于可以使用c3p0的连接池了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值