您的位置:首页 > 其它

用IMAP4访问Exchange邮箱:Exchange2003系列之七

2010-02-24 17:32 302 查看
网上有很多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网站有一篇 HowTo configure the C3P0 connection pool,里面讲的也还是配置这几项,下面有人回帖说如果想让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这个属性才行,在配置文件里加上
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
再次运行,终于可以使用c3p0的连接池了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: