---
title: "hibernate.cfg.xml文件详解 "
author: "cfeers"
date: "2010-08-26T15:56:28Z"
tags: []
categories: ["企业架构"]
slug: "hibernate-cfg-xml"
draft: false
lastmod: "2010-08-26T15:56:28Z"
id: 747923
url: "https://cfeers.iteye.com/blog/747923"
---

&lt;?xml version='1.0' encoding='utf-8'?&gt;  
&lt;!DOCTYPE hibernate-configuration PUBLIC  
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
        "[http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd](http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd)"&gt;　　

&lt;hibernate-configuration&gt;　　

    &lt;session-factory&gt;　　

        &lt;!--  数据库连接设置 --&gt;  
        &lt;property name="connection.driver\_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;  
        &lt;property name="connection.url"&gt;jdbc:mysql://localhost/hibernate&lt;/property&gt;  
        &lt;property name="connection.username"&gt;root&lt;/property&gt;  
        &lt;property name="connection.password"&gt;root&lt;/property&gt;　　

        &lt;!-- JDBC connection pool (use the built-in) --&gt;  
        &lt;!-- &lt;property name="connection.pool\_size"&gt;1&lt;/property&gt;--&gt;　　

        &lt;!-- SQL dialect 方言 --&gt;        
        &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;  
         
        &lt;!-- Enable Hibernate's automatic session context management --&gt;  
        &lt;!-- &lt;property name="current\_session\_context\_class"&gt;thread&lt;/property&gt;--&gt;　　

        &lt;!-- Disable the second-level cache 2级缓存 --&gt;  
        &lt;property name="cache.provider\_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;　　

        &lt;!--    show\_sql   生成sql语句 --&gt;  
        &lt;property name="show\_sql"&gt;true&lt;/property&gt;          
         &lt;!--   format\_sql  生成更漂亮的sql语句 --&gt;  
        &lt;property name="format\_sql"&gt;true&lt;/property&gt;　　

        &lt;!-- 取值 validate | update | create | create-drop  --&gt;  
        &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;  　　

        **&lt;!-- 添加实体类的映射文件  --&gt;**  
        **&lt;mapping resource="com/cfeers/hibernate/model/Student.hbm.xml"/&gt;**  
         **&lt;!-- Annotation方式配置   --&gt;**  
        **&lt;mapping class="com.cfeers.hibernate.model.Teacher"/&gt;**                    
    &lt;/session-factory&gt;　　

&lt;/hibernate-configuration&gt;