1.Hibernate ORM及c3p0的问题
在使用hibernate ORM 4.3.9时发现,hibernate附带的c3p0连接池不起作用.使用的数据库是MySql5.6
下载 hibernate 并解压后,可以在 lib/optional/c3p0 下发现c3po连接池实现类。在 documentation/devguide/en-US/html_single/index.html 可以找到配置c3p0的文档。
将lib/required下的所有jar和lib/optional/c3p0所有jar 加到Java程序的classpath.
按照文档说明 org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
应该是 ConnectionProvider接口的实现.但在所有jar包中没有找到这个类,这应该是文档的一个bug.
打开 lib\optional\c3p0\hibernate-c3p0-4.3.9.Final.jar 发现 org\hibernate\c3p0\internal\C3P0ConnectionProvider.class 实现了ConnectionProvider (org.hibernate.engine.jdbc.connections.spi.ConnectionProvider) .因此将hibernate.connection.provider_class改写为
hibernate.connection.provider_class=org.hibernate.c3p0.internal.C3P0ConnectionProvider
hibernate.properties 配置池的最小值是1,最大值是10.如下所示
hibernate.connection.driver_class =com.mysql.jdbc.Driver
hibernate.connection.url =jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8
hibernate.connection.username =User001
hibernate.connection.password =XXX
hibernate.connection.provider_class=org.hibernate.c3p0.internal.C3P0ConnectionProvider
hibernate.c3p0.min_size=1
hibernate.c3p0.max_size=10
hibernate.c3p0.timeout= 10 #秒对应于c3p0的?
hibernate.c3p0.max_statements&#