在Hibernate里配置Proxool连接池

1. 需要jar文件

proxool-cglib.jar

proxool-0.9.1.jar

下载地址:http://proxool.sourceforge.net

proxool-0.9.1 中包含这两个jar文件,其中proxool-0.9.1.jar地址需要放在环境变量classpath中.

2.修改hibernate.cfg.xml文件.

 

在文件中增加下面内容:

<property name="hibernate.proxool.pool_alias">pool1</property> 
<property name="hibernate.proxool.xml">ProxoolConf.xml</property> 
<property name="hibernate.connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</property>

 

依次是连接池别名,对应xml文件及驱动,整个文件如下:

 

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

 <session-factory>
 
  <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
  <property name="myeclipse.connection.profile">OracleServer</property>    
  
  <property name="show_sql">true</property><!--显示sql语句-->
  <property name="format_sql">true</property><!--使显示的sql语句格式化-->
  <!-- 解决"ClassNotFoundException: org.hibernate.hql.ast.HqlToken"异常 -->
  <property name="hibernate.query.factory_class">
   org.hibernate.hql.classic.ClassicQueryTranslatorFactory
  </property>
  <!-- 解决"java.sql.SQLException: 不允许的操作: streams type cannot be used in batching" -->
  <property name="hibernate.jdbc.batch_size">0</property>
  
<property name="hibernate.proxool.pool_alias">pool1</property>
  <property name="hibernate.proxool.xml">ProxoolConf.xml</property>
  <property name="hibernate.connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</property>

  
  <mapping
   resource="com/netinfo/struts/domain/domain00/T0000powerinfo.hbm.xml" />
 </session-factory>
</hibernate-configuration>

 

3.增加ProxoolConf.xml文件,放在hibernate.cfg.xml文件同级目录下.

 

<?xml version="1.0" encoding="utf-8"?>
<!-- the proxool configuration can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->

<something-else-entirely>
    <proxool>
        <alias>pool1</alias>
<!--proxool只能管理由自己产生的连接-->
        <driver-url>jdbc:mysql://localhost:3306/struts?useUnicode=true&characterEncoding=GBK</driver-url>
        <driver-class>org.gjt.mm.mysql.Driver</driver-class>
        <driver-properties>
            <property name="user" value="root"/>
            <property name="password" value="8888"/>
        </driver-properties>
<!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁-->
        <house-keeping-sleep-time>90000</house-keeping-sleep-time>
<!-- 指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受-->
        <maximum-new-connections>20</maximum-new-connections>
<!-- 最少保持的空闲连接数-->
        <prototype-count>5</prototype-count>
<!-- 允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定-->
        <maximum-connection-count>100</maximum-connection-count>
<!-- 最小连接数-->
        <minimum-connection-count>10</minimum-connection-count>
    </proxool>
</something-else-entirely>

 

常见错误:

1、org.hibernate.HibernateException: Proxool Provider unable to load JAXP configurator file: proxool.xml
org.logicalcobwebs.proxool.ProxoolException: Parsing failed.

将proxoolconf.xml里面的中文删除即可。

2、proxool-0.8.3.jar中包含了proxool-0.9.1.jar和proxool-cglib.jar 使用proxool-0.9.1.jar记得加上proxool-cglib.jar

 

你可能感兴趣的:(Hibernate)