天天看点

Hibernate核心配置文件hibernate.cfg.xml详解

位置:位于src目录下

命名:hibernate.cfg.xml

案例:

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!-- DTD:用于获取提示信息 -->

<!-- hibernate的配置 -->
<hibernate-configuration>

    <!-- 会话工厂 -->
    <session-factory>
    
        <!-- 配置数据库连接的4个参数 -->
       <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property><!-- 驱动 -->
       <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/shujuku</property><!--地址 -->
       <property name="hibernate.connection.username"><u>zyf</u></property><!-- 用户名 -->
       <property name="hibernate.connection.password">123456</property><!-- 密码 -->
       
        <!-- 是否显示sql语句 -->
       <property name="show_sql">true</property>

       <!-- 是否格式化sql语句 -->
       <property name="format_sql">true</property>

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

       <!-- 配置JavaBean模型类与数据库表的映射文件 -->
       <mapping resource="com/moli/hibernate/domain/User.hbm.xml" />
    
    </session-factory>


</hibernate-configuration>
           

继续阅读