hibernate是一个完全的ORM(Object Relational Mapping,对象关系映射)开源框架。java
Hibernate配置文件有两种形式:XML与properties mysql
我的建议使用XML,由于properties中不能配置关联的映射文件,在后续的实现中会带来一些不必的编码;web
XML(hibernate.cfg.xml)文件详解:算法
<?xml version="1.0" encoding="GBK"?> sql
<!-- 指定Hibernate配置文件的DTD信息 --> 数据库
<!DOCTYPE hibernate-configuration PUBLIC 缓存
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 服务器
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 网络
<!-- hibernate- configuration是链接配置文件的根元素 --> session
<hibernate-configuration>
<session-factory>
<!-- 指定链接数据库所用的驱动 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- 指定链接数据库的url,hibernate链接的数据库名 -->
<property name="connection.url">jdbc:mysql://localhost/数据库名</property>
<!-- 指定链接数据库的用户名 -->
<property name="connection.username">root</property>
<!-- 指定链接数据库的密码 -->
<property name="connection.password">32147</property>
<!-- 指定链接池里最大链接数 -->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 指定链接池里最小链接数 -->
<property name="hibernate.c3p0.min_size">1</property>
<!-- 指定链接池里链接的超时时长 -->
<property name="hibernate.c3p0.timeout">5000</property>
<!-- 指定链接池里最大缓存多少个Statement对象 -->
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property>
<!-- 指定数据库方言 -->
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<!-- 根据须要自动建立数据表 -->
<property name="hbm2ddl.auto">update</property>
<!-- 显示Hibernate持久化操做所生成的SQL -->
<property name="show_sql">true</property>
<!-- 将SQL脚本进行格式化后再输出 -->
<property name="hibernate.format_sql">true</property>
<!-- 罗列全部的映射文件 -->
<mapping resource="映射文件路径/News.hbm.xml"/>
</session-factory>
</hibernate-configuration>
properties(hibernate.properties)文件详解