zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    C#控件开发(三)
    C#控件开发(四)
    如何将方行的按纽改变为其他的形状
    C#绘制圆角矩形
    Win7右键不能新建文件夹
    WinForm窗体FormClosing事件导致无法关机
    反射动态调用WinForm窗口
    C#钩子本线程内消息拦截
    C#控件开发(一)
    七个C#编程小技巧
  • 原文地址:https://www.cnblogs.com/feitianshaoxai/p/6604871.html
Copyright © 2011-2022 走看看