• spring配置hibernate的sessionFactory


    1.首先通过dataSource来配置sessionFactory

      

    <!--读入配置文件 -->
        <bean id="propertyConfigurer"  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                <property name="locations">
                    <value>classpath*:jdbc.properties</value>
                </property>
        </bean>
        
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  destroy-method="close">  
             <property name="driverClassName" value="${jdbc.driverClassName}" />
             <property name="url" value="${jdbc.url}" />
             <property name="username" value="${jdbc.username}" />
             <property name="password" value="${jdbc.password}" />
        </bean> 
        <bean id="sessionFactory"  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.hbm2ddl">update</prop>
                </props>
            </property>
            <property name="mappingResources">
                 <list>
                    <value>classpath*:/test/domain/MyBean.hbm.xml</value>
                    <value>classpath*:/test/domain/BasicBean.hbm.xml</value>
                </list>
            </property>
        </bean>
    applicationContext.xml

    2.通过Hibernate.cfg.xml来配置sessionFactory

    <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="configLocation"  value="classpath:hibernate.cfg.xml"></property>
    </bean>


    <!--<bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="configLocation"  value="classpath:hibernate.cfg.xml"></property>
    </bean>-->
    <?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.SQLServerDialect
            </property>
            <property name="connection.url">
                jdbc:sqlserver://localhost:1433
            </property>
            <property name="connection.username">sa</property>
            <property name="connection.password">123456</property>
            <property name="connection.driver_class">
                com.microsoft.sqlserver.jdbc.SQLServerDriver
            </property>
            <property name="myeclipse.connection.profile">
                SQLServerDriver
            </property>
            <property name="show_sql">true</property>
            <property name="connection.autocommit">true</property>
            <mapping
                resource="com/chinasoft/graduation/entity/MyCourse.hbm.xml" />
            <mapping
                resource="com/chinasoft/graduation/entity/Students.hbm.xml" />
            <mapping
                resource="com/chinasoft/graduation/entity/Course.hbm.xml" />
            <mapping
                resource="com/chinasoft/graduation/entity/Annoucement.hbm.xml" />
        </session-factory>
    
    </hibernate-configuration>
    Hibernate.cfg.xml
  • 相关阅读:
    jQuery.getJSON的缓存问题的解决办法
    MFC Tab Control控件的详细使用
    JavaScript 闭包深入理解(closure)
    STL中sort函数用法简介
    STL中qsort的七种用法
    学习Javascript闭包(Closure)
    使用 Visual Studio 分析器找出应用程序瓶颈
    各种语言性能测试工具一览表
    Javascript 链式作用域
    MessageBox、::MessageBox 、AfxMessageBox三者的区别 .
  • 原文地址:https://www.cnblogs.com/feitianshaoxai/p/6604871.html
Copyright © 2020-2023  润新知