Hibernate核心配置文件详解

名字必须为hibernate.cfg.xml

文件的位置必须放在src目录下

 

<hibernate-configuration>
    <session-factory>
        <!--数据库驱动-->
       
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <!--数据库地址-->
       
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate01</property>
        <!--数据库账号-->
       
<property name="hibernate.connection.username">root</property>
        <!--数据库密码-->
       
<property name="hibernate.connection.password">root</property>
        <!--方言  必须要设置-->
       
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <!--在控制台展示sql语句-->
       
<property name="hibernate.show_sql">true</property>
        <!--sql语句格式化输出-->
       
<property name="hibernate.format_sql">true</property>
        <!--
        1
、update 如果映射文件和数据库表一致就不修改,如果没有这个表会自动创建表
        2
、create 每次执行都会重新创建一个表
        3
、create-drop 先将原来的表删除,然后重新创建
        4
、validate 只做校验,不修改表
        -->
       
<property name="hibernate.hbm2ddl.auto">update</property>
        <!--事务的隔离级别
       
脏读
       
幻读
       
不可重复读
       
串行化
        -->
       
<property name="hibernate.connection.isolation">4</property>
        <!--扫描映射文件
        class
必须 映射文件和配置文件名字和路径一致
        package
扫描该包下面的所有配置文件
        resource
指定某个确定的xml配置文件
        -->
       
<mapping resource="cn/hd/bean/user.hbm.xml"></mapping>

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

猜你喜欢

转载自blog.csdn.net/qq_41554789/article/details/81080245