• 【SSH】spring 整合 hibernate


    spring-hibernate-1.2.9.jar

    applicationContext.xml

        <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"></property>
            <!-- //加载实体类的映射文件位置及名称 -->
            <property name="mappingLocations" value="classpath:k/bean/*.hbm.xml"></property>
            <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
        </bean>

    hibernate.cfg.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">
    <hibernate-configuration>
        <session-factory>
            <!-- 配置Hibernate的基本属性 -->
            <!-- 1.数据源配置到IOC容器中 -->
            <!-- 2.关联的.hbm.xml也在IOC容器配置SessionFactory实例 -->
            <!-- 3.配置Hibernate的基本属性:方言,SQL显示及格式化,生成数据表的策略以及二级缓存 -->
            <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
            <property name="hibernate.hbm2ddl.auto">update</property>
            <property name="hibernate.show_sql">true</property>
            <property name="hibernate.format_sql">true</property>
            <property name="cache.use_second_level_cache">true</property>
            <property name="ache.provider_class">org.hibernate.cache.internal.DefaultCacheKeysFactory</property>
            <property name="generate_statistics">true</property>
        </session-factory>
    </hibernate-configuration>

    Employee.hbm.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC
            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
        <class name="k.domain.Employee" table="t_employee">
            <id name="id" column="id" type="java.lang.Integer">
                <!-- 设置数据库表id增长策略  native:生成表id值就是主键自动增长  uuid -->
                <generator class="native"></generator>
            </id>
            <!-- 配置其他属性和表字段对应  name属性:实体类属性名称 column属性:生成表字段名称 -->
            <property name="name" column="name" type="java.lang.String" length="64"></property>
            <property name="email" column="email" type="java.lang.String" length="64"></property>
            <property name="hireDate" column="hireDate" type="java.util.Date"></property>
            <property name="salary" column="salary" type="java.lang.Float"></property>
            <property name="password" column="password" type="java.lang.String" length="64"></property>
            <property name="grade" column="grade" type="java.lang.Integer" length="3"></property>
            <many-to-one name="department" class="k.domain.Department" column="department_id"></many-to-one>
        </class>
    </hibernate-mapping>

    Spring整合Hibernate详细步骤

  • 相关阅读:
    pku2704 Pascal's Travels
    MFC中获取各种类指针的方法 (转)
    VC中MessageBox的常见用法
    直接通过ADO操作Access数据库(转)
    (转)基于MapWinGis开发探索(三)改善缩放、渲染、显示文本
    VC画线几个常见方法
    虚拟现实技术发展的新趋势(转)
    (转)基于MapWinGis开发探索(二)——注册、加载、基本操作
    基于MFC的对话框程序加启动进度条
    IT应用新动向 未来需要云计算
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/12327670.html
Copyright © 2020-2023  润新知