SSH与SSM学习之hibernate03——主配置详解

SSH与SSM学习之hibernate03——主配置详解

一、配置相关的文件获取

我们下载包以后解压可以去下面这个位置找到全部配置相关的文件

project\etc

有如下的配置文件

ehcache.xml   (二级缓存配置)
hibernate.cfg.xml (hibernate的主配置文件)
hibernate.properties (这里可以找到主配置文件中,能够配置的选项)
hibernate.properties.template
hibernate-service.xml
log4j.properties  (日志配置)

二、我们的主配置文件

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!--数据库驱动-->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <!--数据库url-->
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/htest</property>
        <!--数据库连接用户名-->
        <property name="hibernate.connection.username">root</property>
        <!--数据库连接密码-->
        <property name="hibernate.connection.password">xm123456</property>
        <!--数据库方言-->
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <!--自动创建表-->
        <property name="hibernate.hbm2ddl.auto">update</property>

        <!--导入 User 配置-->
        <mapping resource="com/qwm/hilbernate01/user.hbm.xml"/>

    </session-factory>
</hibernate-configuration>

三、必选属性配置(5个)

      <!--数据库驱动-->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <!--数据库url-->
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/htest</property>
        <!--数据库连接用户名-->
        <property name="hibernate.connection.username">root</property>
        <!--数据库连接密码-->
        <property name="hibernate.connection.password">xm123456</property>
        <!--数据库方言-->
        <!-- 数据库方言
            不同的数据库中,sql语法略有区别. 指定方言可以让hibernate框架在生成sql语句时.针对数据库的方言生成.
            sql99标准: DDL 定义语言  库表的增删改查
                       DCL 控制语言  事务 权限
                      DML 操纵语言  增删改查
         -->
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

四、可选属性配置(3个)

<!-- 将hibernate生成的sql语句打印到控制台 -->
<property name="hibernate.show_sql">true</property>
<!-- 将hibernate生成的sql语句格式化(语法缩进) -->
<property name="hibernate.format_sql">true</property>
<!-- 
## auto schema export  自动导出表结构. 自动建表
#hibernate.hbm2ddl.auto create      自动建表.每次框架运行都会创建新的表.以前表将会被覆盖,表数据会丢失.(开发环境中测试使用)
#hibernate.hbm2ddl.auto create-drop 自动建表.每次框架运行结束都会将所有表删除.(开发环境中测试使用)
#hibernate.hbm2ddl.auto update(推荐使用) 自动生成表.如果已经存在不会再生成.如果表有变动.自动更新表(不会删除任何数据).
#hibernate.hbm2ddl.auto validate    校验.不自动生成表.每次启动会校验数据库中表是否正确.校验失败.
 -->
<!--自动创建表-->
<property name="hibernate.hbm2ddl.auto">update</property>

五、元数据引入配置


<!--导入 User 配置-->
<!-- 引入orm元数据
    路径书写: 填写src下的路径
 -->
<mapping resource="com/qwm/hilbernate01/user.hbm.xml"/>

六、全部的标注

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!--数据库驱动-->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <!--数据库url-->
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/htest</property>
        <!--数据库连接用户名-->
        <property name="hibernate.connection.username">root</property>
        <!--数据库连接密码-->
        <property name="hibernate.connection.password">xm123456</property>
        <!--数据库方言-->
        <!-- 数据库方言
            不同的数据库中,sql语法略有区别. 指定方言可以让hibernate框架在生成sql语句时.针对数据库的方言生成.
            sql99标准: DDL 定义语言  库表的增删改查
                       DCL 控制语言  事务 权限
                      DML 操纵语言  增删改查
         -->
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <!-- #hibernate.show_sql true
     #hibernate.format_sql true
-->
        <!-- 将hibernate生成的sql语句打印到控制台 -->
        <property name="hibernate.show_sql">true</property>
        <!-- 将hibernate生成的sql语句格式化(语法缩进) -->
        <property name="hibernate.format_sql">true</property>
        <!--
        ## auto schema export  自动导出表结构. 自动建表
        #hibernate.hbm2ddl.auto create      自动建表.每次框架运行都会创建新的表.以前表将会被覆盖,表数据会丢失.(开发环境中测试使用)
        #hibernate.hbm2ddl.auto create-drop 自动建表.每次框架运行结束都会将所有表删除.(开发环境中测试使用)
        #hibernate.hbm2ddl.auto update(推荐使用) 自动生成表.如果已经存在不会再生成.如果表有变动.自动更新表(不会删除任何数据).
        #hibernate.hbm2ddl.auto validate    校验.不自动生成表.每次启动会校验数据库中表是否正确.校验失败.
         -->
        <!--自动创建表-->
        <property name="hibernate.hbm2ddl.auto">update</property>

        <!--导入 User 配置-->
        <!-- 引入orm元数据
            路径书写: 填写src下的路径
         -->
        <mapping resource="com/qwm/hilbernate01/user.hbm.xml"/>

    </session-factory>
</hibernate-configuration>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值