hibernate配置文件详解

hibernate配置文件

hibernate的配置文件在hibernate.cfg.xml文件中编写

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- 配置连接数据库信息 -->
        <property name="connection.url">jdbc:mysql://localhost:3306/studyhibernate</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.username">root</property>
        <property name="connection.password">123456</property>

       <!-- JDBC connection pool 数量 -->
        <property name="connection.pool_size">1</property>
        <!-- 配置hibernate的基本信息 -->
        <!-- hibernate方言 -->
        <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <!-- 执行操作时是否在控制台打印 -->
        <property name="show_sql">true</property>
        <!-- 是否对SQL进行格式化 -->
        <property name="format_sql">true</property>
        <!-- 指定自动生成数据表的策略 -->
        <!--
            取值可以有create、update、create-drop、validate
            - create  根据.hbm.xml文件来生成数据表,但是每次运行都会删除上一次的表,重新生成表
            - create-drop 根据.hbm.xml文件生成表,sessionFactory关闭,表会自动删除
            - update  根据.hbm.xml文件生成表,但若.hbm.xml文件和数据库中对应的数据表的表结构不同,hibernate会跟新数据表结构,但不会删除已有的行和列
            - validate  和数据库的表进行比较,若.hbm.xml文件中的列在数据表中不存在,则抛出异常

        -->

        <property name="hibernate.hbm2ddl.auto">update</property>
        <!-- DB schema will be updated if needed -->
        <!-- <property name="hibernate.hbm2ddl.auto">update</property> -->
       <!-- session管理方式 -->
        <property name="current_session_context_class">thread</property>

        <!-- 启用二级缓存 -->
        <property name="cache.use_second_level_cache">false</property>
        <!-- 二级缓存指定第三方插件 -->
        <!--<property name="hibernate.cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>-->
        <!-- 开启查询缓存 -->
        <!--<property name="cache.use_query_cache">true</property>-->

        <!--<property name="current_session_context_class">thread</property>-->
        <!-- 指定关联的映射文件 -->
        <mapping resource="User.hbm.xml"/>
        <mapping resource="Customer.hbm.xml"/>
        <mapping resource="Order.hbm.xml"/>
        <mapping resource="Department.hbm.xml"/>
        <mapping resource="Manager.hbm.xml"/>
        <!-- 配置哪个类使用二级缓存 -->
        <!--<class-cache class="com.zhanghe.study.model.User" usage="read-write"/>
        <collection-cache collection="com.zhanghe.study.model.many2one.Customer.orderList" usage="read-write"/>
        <class-cache class="com.zhanghe.study.model.many2one.Order" usage="read-write"/>-->

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

https://zhhll.icu/2020/框架/hibernate/基础/2.hibernate配置文件/

本文由 mdnice 多平台发布

  • 10
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

拾光师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值