Hibernate-hibernate.cfg.xml基础配置

<?xml version="1.0" encoding="UTF-8"?>
<!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 元素用于配置Hibernate中的属性
            键:值
          -->
          <!-- hibernate.connection.driver_class : 连接数据库的驱动  -->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

          <!-- hibernate.connection.username : 连接数据库的用户名 -->
        <property name="hibernate.connection.username">root</property>

          <!-- hibernate.connection.password : 连接数据库的密码 -->
        <property name="hibernate.connection.password">123</property>

          <!-- hibernate.connection.url : 连接数据库的地址,路径 -->
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernatedemo</property>

        <!-------------------------------------------------------------------------------->

        <!-- show_sql: 操作数据库时,会 向控制台打印sql语句 -->
        <property name="show_sql">true</property>

        <!-------------------------------------------------------------------------------->

        <!-- format_sql: 打印sql语句前,会将sql语句先格式化  -->
        <property name="format_sql">true</property>

        <!-------------------------------------------------------------------------------->

        <!-- hbm2ddl.auto: 生成表结构的策略配置
             update(最常用的取值): 如果当前数据库中不存在表结构,那么自动创建表结构.
                     如果存在表结构,并且表结构与实体一致,那么不做修改
                     如果存在表结构,并且表结构与实体不一致,那么会修改表结构.会保留原有列.
             create(很少):无论是否存在表结构.每次启动Hibernate都会重新创建表结构.(数据会丢失)
             create-drop(极少): 无论是否存在表结构.每次启动Hibernate都会重新创建表结构.每次Hibernate运行结束时,删除表结构.
             validate(很少):不会自动创建表结构.也不会自动维护表结构.Hibernate只校验表结构. 如果表结构不一致将会抛出异常.
          -->
        <property name="hbm2ddl.auto">update</property>

        <!-------------------------------------------------------------------------------->

        <!-- 数据库方言配置
         org.hibernate.dialect.MySQLDialect (选择最短的)
         -->
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-------------------------------------------------------------------------------->

        <!-- hibernate.connection.autocommit: 事务自动提交  -->
        <property name="hibernate.connection.autocommit">true</property>

        <!-------------------------------------------------------------------------------->

        <!-- 将Session与线程绑定=> 只有配置了该配置,才能使用getCurrentSession -->
        <property name="hibernate.current_session_context_class">thread</property>

        <!-------------------------------------------------------------------------------->

        <!-- 引入ORM 映射文件
            填写src之后的路径
         -->
        <mapping resource="com/itheima/a_hello/User.hbm.xml"/>
    </session-factory>
</hibernate-configuration>
时间: 2024-08-15 14:07:48

Hibernate-hibernate.cfg.xml基础配置的相关文章

hibernate.cfg.xml常见配置

转载自:http://blog.csdn.net/qiaqia609/article/details/9456489 1 <!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式--> 2 <?xml version='1.0' encoding='gb2312'?> 3 <!--表明解析本XML文件的DTD文档位置,DTD是Document Type Definition 的缩写,即文档类型的定

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"><hi

【Hibernate学习笔记-4】在hibernate.cfg.xml中配置C3P0数据源

jar包 hibernate.cfg.xml <?xml version="1.0" encoding="GBK"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.d

Hibernate.cfg.xml 主配置

<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <!-- 映射文件: 映射一个实体类对象:  描述一个对象最终实现可以直接保存对象数据到数据库中. 

hibernate学习笔记_基础配置

一.hibernate.cfg.xml: hbni2ddl.auto 二.搭建日志环境并配置显示DDL语句 我们使用slf接口,然后使用log4j的实现. 1.  首先引入log4j的jar包(log4j-1.2.14.jar), 2.  然后再引入slf4j实现LOG4J和适配器jar包(slf4j-log4j12-1.5.8.jar) 3.  最后创建log4j的配置文件(log4j.properties),并加以修改,只要保留 log4j.logger.org.hibernate.tool

hibernate--hibernate.cfg.xml常用配置详解

在hibernate中最重要的两个配置文件就是hibernate.cfg.xml和xxx.hbm.xml文件,前者是一些配置信息,后者是配置表和对象的映射关系,可以通过注解的方式来取代. 本篇文章主要详细讨论下hibernate.cfg.xml文件的配置. 首先hibernate.cfg.xml的模板文件在hibernate-release-5.2.7.Final\project\etc\hibernate.cfg.xml就有.

spring整合hibernate的applicationContext.xml文件配置以及web.xml

applicationContext.xml文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.spri

hibernate 在web.xml中配置的作用

1. <filter>     <filter-name>Spring character encoding filter</filter-name>     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>     <init-param>       <param-name>encoding</p

Spring整合Hibernate的时候使用hibernate.cfg.xml

Spring整合Hibernate其实也就是把Hibernate的SessionFactory对象封装成:org.springframework.orm.hibernate3.LocalSessionFactoryBean 在由自己来保管和控制. 在配置LocalSessionFactoryBean的时候,如果要用到hibernate.cfg.xml配置文件,那么就要配置: configLocations属性,这个属性就是叫Spring在配置LocalSessionFactoryBean的时候去