<?xml version="1.0" encoding="UTF-8"?>
<!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>
<!-- 数据库连接要素 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/mytestdb</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<!-- 指定方言文件 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- 指定数据库连接池,注释部分为Hibernate内置连接池 -->
<!-- <property name="hibernate.connection.provider_class">
org.hibernate.c3p0.internal.C3P0ConnectionProvider</property> -->
<!-- 指定session上下文,确保在同一线程中使用的session是同一个 -->
<property name="hibernate.current_session_context_class">thread</property>
<!-- 自动建表 -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 展示经代码格式化后的SQL语句 -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<!-- 设置事务的隔离级别 -->
<property name="hibernate.connection.isolation">4</property>
<!-- 开启Query缓存 -->
<!-- <property name="hibernate.cache.use_query_cache">true</property> -->
<!-- 开启二级缓存 -->
<property name="hibernate.cache.use_second_level_cache">true</property>
<!-- 注册二级缓存区域工厂 -->
<property name="hibernate.cache.region.factory_class">
org.hibernate.cache.ehcache.internal.EhcacheRegionFactory</property>
<!-- 注册映射文件 -->
<mapping resource="beans/Minister.bhm.xml" />
<mapping resource="beans/Country.bhm.xml" />
<!-- 主配置文件集中管理类缓存 -->
<class-cache usage="read-only" class="beans.Country"/>
<class-cache usage="read-only" class="beans.Minister"/>
<!-- 主配置文件集中管理集合缓存 -->
<collection-cache usage="read-only" collection="beans.Country.ministers"/>
</session-factory>
</hibernate-configuration>