spring加载hibernate里的sessionfactory的三种方式

方式1:只加载SessionFactory

   <beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

        <propertyname="configLocation" value="classpath:hibernate.cfg.xml"></property>

   </bean>

方式2:加载数据库连接池

 <bean id="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

       <propertyname="dataSource" ref="dataSource"></property>

       <propertyname="configLocation"value="classpath:hibernate.cfg.xml"></property>

    </bean>

方式3:加载所有属性

 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

       <!-- a. 注入连接池 -->

       <property name="dataSource" ref="dataSource"></property>

      

       <!-- b. hibernate常用配置:方言、自动建表、显示sql -->

       <property name="hibernateProperties">

           <props>

               <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>

               <prop key="hibernate.show_sql">true</prop>

               <prop key="hibernate.hbm2ddl.auto">update</prop>

           </props>

       </property>

      

       <!-- c. 加载所有的映射(根据路径加载)

       <propertyname="mappingLocations">

           <list>

               <value>classpath:cn/itcast/entity/*.hbm.xml</value>

           </list>

       </property>

       -->

       <!-- c. 根据目录加载所有的映射 -->

       <property name="mappingDirectoryLocations">

           <list>

               <value>classpath:cn/itcast/entity</value>

           </list>

       </property>

    </bean>

========================================hibernate配置数据库连接池======================

    <session-factory>
        <!-- 一、 数据库连接的参数配置 -->
        <property name="hibernate.connection.url">jdbc:mysql:///hib_demo</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    
        <!-- 二、 hibernate其他常用配置 -->
        <property name="hibernate.show_sql">true</property>
        <!--<property name="hibernate.format_sql">true</property>-->
        <property name="hibernate.hbm2ddl.auto">update</property>
        
        <!--
            hibernate对连接池的支持
         -->
         <!-- C3p0连接池支持类 -->
         <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
         <!-- 最大连接数 -->
         <property name="hibernate.c3p0.max_size">6</property>
         <!-- 最小连接数 -->
         <property name="hibernate.c3p0.min_size">4</property>
         <!-- 当连接不够用时候每次的增量 -->
         <property name="hibernate.c3p0.acquire_increment">2</property>
         <!-- 最多执行的命令的个数 -->
         <property name="hibernate.c3p0.max_statements">100</property>
         <!-- 连接空闲测试时间 -->
         <property name="hibernate.c3p0.idle_test_period">3000</property>
        
        
         <!-- 配置session的创建方式,线程方式创建session -->
         <property name="hibernate.current_session_context_class">thread</property>
     

............................ 
   </session-factory>

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值