hibernate.cfg.xml的配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yhld456/article/details/52563085

hibernate.cfg.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>
    <!-- 1、配置数据库连接信息
        支持jdbc
        连接池
     -->
     <!-- 数据库驱动 -->
    <property name="connection.driver_class">
        com.mysql.jdbc.Driver
    </property>
    <!-- 连接url
    jdbc:mysql:///hibernate4
    相当于下面的
     -->
    <property name="connection.url">
        jdbc:mysql://localhost:3306/hibernate4?useUnicode=true&amp;characterEncoding=utf-8
    </property>
    <property name="connection.username">root</property>
    <property name="connection.password">123456</property>
    <!-- 2、hibernate可选项信息 -->
    <!-- 数据库方言 -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <!-- 配置是否打印sql语句 -->
    <property name="show_sql">true</property>
    <!-- 格式化sql语句 -->
    <property name="format_sql">true</property>
    <!-- 数据库的更新方法
        create:每次执行都先把原有数据表删掉,然后创建该表
        create-drop:在显示关闭SessionFactory时删除对应的数据表
        validate:检测存在与否
        update:发现没有表的时候创建表,如果有就不用创建
     -->
    <property name="hbm2ddl.auto">update</property>
    <!-- 3、映射文件信息 -->
    <mapping resource="com/pojo/User.hbm.xml" />
</session-factory>
</hibernate-configuration>

猜你喜欢

转载自blog.csdn.net/yhld456/article/details/52563085