Hibernate pool资料收集

原创 2006年06月08日 22:45:00

简化后的spring+hibernate配置
spring部分:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <!--
            加入spring后,把dataSource定义交给hibernate.cfb.xml,感觉hibernat部分要完整些,与没加入spring基本没区别(不知道是好事还是坏事)
            <property name="dataSource">
            <ref bean="dataSource" />
            </property>
        -->
        <property name="configLocation">
            <value>classpath:/mapping/hibernate.cfg.xml</value>
        </property>
    </bean>
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref local="sessionFactory" />
        </property>
    </bean>

    <bean id="AbstractDAOProxy"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
        abstract="true">
        <property name="transactionManager">
            <ref bean="transactionManager" />
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="*">PROPAGATION_REQUIRED</prop>
            </props>
        </property>
    </bean>
    <bean id="UserDAO"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
        parent="AbstractDAOProxy">
        <property name="target">
            <!--
                   DAO直接定义在这儿,省得单独定义一个bean id="xxxxDAO"
                   由于是测试工程,就直接由测试代码操作DAO,不写services了
              -->
            <bean class="dao.UserDAOHibernate">
                <property name="sessionFactory">
                    <ref local="sessionFactory" />
                </property>
            </bean>
        </property>
    </bean>
</beans>

Hibernate.cfb.xml 部分(与没使用spring相同)
<?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" >
<hibernate-configuration>
    <session-factory name="spring_hibernate">
        <property name="hibernate.connection.driver_class">
            oracle.jdbc.driver.OracleDriver
        </property>
        <property name="hibernate.connection.url">
            jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS =
            (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521)) )
            (CONNECT_DATA = (SID = xx)(SERVER = DEDICATED)) )
        </property>
        <property name="hibernate.connection.username">xxxx</property>
        <property name="hibernate.connection.password">
            xxxxxxxxxxxx
        </property>
        <property name="hibernate.dbcp.maxActive">100</property>
        <property name="hibernate.dbcp.whenExhaustedAction">1</property>
        <property name="hibernate.dbcp.maxWait">120000</property>
        <property name="hibernate.dbcp.maxIdle">10</property>
        <property name="hibernate.dialect">
            org.hibernate.dialect.OracleDialect
        </property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">create-drop</property>
        <property name="hibernate.cache.provider_class">
            org.hibernate.cache.OSCacheProvider
        </property>
        <mapping resource="mapping/People.hbm.xml" />
        <mapping resource="mapping/Lob.hbm.xml" />
        <class-cache usage="read-only" class="domain.People" />
    </session-factory>
</hibernate-configuration>

 

 

 

 

 

 

最近用hibernate做东西,结合上网查一些资料,总结出Hibernate中连接数据的几种经典方式的Hibernate.cfg.xml文件配置,奉献出来,我调试通过:
第一种:用jdbc连接的配置                

<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://localhost:3306/sample</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="myeclipse.connection.profile">localhost</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<mapping resource="com/lzb/TUser.hbm.xml"></mapping>

第二种:用c3p0连接池的配置:

在hibernate.cfg.xml中加入

<!-- JDBC驱动程序 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/sample</property>
<property name="connection.password">root</property>
<property name="connection.username">root</property>
<!-- c3p0连接池的配置,它会自动调用jdbc驱动,管理数据库的连接 -->                
<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>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">120</property>
<property name="hibernate.c3p0.acquire_increment">2</property>


第三种:用proxool连接池的配置:

在hibernate.cfg.xml中加入

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

然后,在和hibernate.cfg.xml同一个目录下,加一个ProxoolConf.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/sample</driver-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="root"/>
<property name="password" value="root"/>
</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>

 

 

 

 

 

hibernate.connection.driver_class=COM.ibm.DB2.JDBC.net.DB2Driver
hibernate.connection.url=jdbc:db2://server1/sample
hibernate.connection.username=db2admin
hibernate.connection.password=password
hibernate.default_schema=db2admin
hibernate.dialect=net.sf.hibernate.dialect.DB2Dialect
hibernate.show_sql=true
# The maximum number of active connections that can be allocated # from this pool at the same time, or zero for no limit.
hibernate.dbcp.maxActive 100
# Action to take in case of an exhausted DBCP statement pool
# ( 0 = fail, 1 = block, 2= grow)
hibernate.dbcp.whenExhaustedAction 1
hibernate.dbcp.maxWait 120000
# The maximum number of active connections that can remain
# idle in the pool, without extra ones being released, or zero
# for no limit.
hibernate.dbcp.maxIdle 10
# The SQL query that will be used to validate
# connections from this pool before returning them to the caller.
# hibernate.dbcp.validationQuery=TODO
## prepared statement cache
hibernate.dbcp.ps.maxActive 100
# Action to take in case of an exhausted DBCP statement
#pool ( 0 = fail, 1 = block, 2= grow)
hibernate.dbcp.ps.whenExhaustedAction 1
# The maximum number of milliseconds that the pool will
# wait (when there are no available connections) for a connection
# to be returned before throwing an exception, or -1 to
# wait indefinitely.
hibernate.dbcp.ps.maxWait 120000
hibernate.dbcp.ps.maxIdle 100

 

 

 

相关文章推荐

memory pool资料

备份资料 引用自http://www-128.ibm.com/developerworks/cn/linux/l-memory/?ca=dwcn-newsletter-linux#resources...

Spring Hibernate4 连接几次后连接异常, Cannot get a connection, pool error Timeout waiting for idle object

之前我是通过 把SessionFactory的对象注入到Dao层,然后用OpenSession的方法去操作数据库,出现了标题的错误. 然后问题的原因我也不知道,我现在改成这样getCurrentSe...

在OSGi环境下配置hibernate的connection pool

很多人都知道MySQL的默认设置中含有一个connection timeout属性,当一个connection在8小时之内没有使用的话,就会timeout。在web系统开发中,比如一个用户今天下午下...

INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)的解决

今天按照学习视频学习了Hibernate的入门课程: 前提:用的mysql数据库 前提:导入了hibernate的jar包和JUnit4.0的jar包,还有mysql的jdbc驱动jar包,就是这货:...

How to configure the C3P0 connection pool in Hibernate

Connection PoolConnection pool is good for performance, as it prevents Java application create a con...

Hibernate 经典学习资料

1.Hibernate基本概念   1)Hibernate有什么作用     a.Hibernate框架主要用于对数据库操作,是对JDBC的封装.在应用程序中实现数据访问层.     b.Hib...

【备忘】经典视频大放送__汤阳光Hibernate框架视频资料

01__Hibernate入门基础.avi 02__Hibernate的学习路线图1.avi 03__第一个Hibernate程序之准备场景.avi 04__第一个Hibernate程序之实现功...

Hibernate中的Open Session In View的资料(英语版)

The problemA common issue in a typical (web-)application is the rendering of the view, after the mai...

hibernate中的session中的方法(网页资料整理)

Session接口的API Method Summary  Transaction beginTransaction()          ...

Hibernate框架ORM的实现原理(资料)

1.什么是ORM ORM的全称是Object Relational Mapping,即对象关系映射。它的实现思想就是将关系数据库中表的数据映射成为对象,以对象的形式展现,这样开发人员就可以把对数据库...
  • xywlzd
  • xywlzd
  • 2012年10月23日 09:24
  • 214
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Hibernate pool资料收集
举报原因:
原因补充:

(最多只允许输入30个字)