c3p0在hibernate中的配置

来源:互联网 发布:mac查看nginx安装目录 编辑:程序博客网 时间:2024/06/02 20:43
c3p0在hibernate.cfg.xml文件里面加入如下的配置:
<!--C3P0配置 -->        <property name="hibernate.connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</property>
<!-- 最大连接数 --><property name="hibernate.c3p0.max_size">20</property><!-- 最小连接数 --><property name="hibernate.c3p0.min_size">5</property><!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 --><property name="hibernate.c3p0.timeout">120</property><!-- 最大的PreparedStatement的数量 --><property name="hibernate.c3p0.max_statements">100</property><!-- 每隔120秒检查连接池里的空闲连接 ,单位是秒--><property name="hibernate.c3p0.idle_test_period">120</property><!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 --><property name="hibernate.c3p0.acquire_increment">2</property><!-- 每次都验证连接是否可用 --><property name="hibernate.c3p0.validate">true</property>
一定要记得写上<property name="hibernate.connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</property>
这一句用于指定Hibernate的连接提供方式,如果没有将不会使用c3p0作为Hibernate的连接池。