BBS项目使用mysql的Hibernate配置文件实例
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<!-- 数据库连接信息 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql:///itcastbbs</property>
<property name="connection.username">root</property>
<property name="connection.password">1234</property>
<!-- 其他配置 -->
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%使用c3p0连接池%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- 最大连接数 -->
<property name="hibernate.c3p0.max_size">25</property>
<!-- 最小连接数 -->
<property name="hibernate.c3p0.min_size">5</property>
<!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 -->
<property name="hibernate.c3p0.timeout">1800</property>
<!-- 最大的PreparedStatement的数量 -->
<property name="hibernate.c3p0.max_statements">100</property>
<!-- 每隔120秒检查连接池里的空闲连接 ,单位是秒-->
<property name="hibernate.c3p0.idle_test_period">120</property>
<!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->
<property name="hibernate.c3p0.acquire_increment">2</property>
<!-- 每次都验证连接是否可用 -->
<property name="hibernate.c3p0.validate">true</property>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%使用EHCache二级缓存%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_query_cache">true</property>
<!-- 类型的定义,要放到第一位 -->
<mapping resource="cn/itcast/bbs/domain/hibernate/CustomValueTypeDefinition.hbm.xml" />
<!-- 声明映射文件 -->
<mapping resource="cn/itcast/bbs/domain/User.hbm.xml" />
<mapping resource="cn/itcast/bbs/dd/DataItem.hbm.xml" />
<mapping resource="cn/itcast/bbs/domain/Category.hbm.xml" />
<mapping resource="cn/itcast/bbs/domain/Forum.hbm.xml" />
<mapping resource="cn/itcast/bbs/domain/Article.hbm.xml" />
<mapping resource="cn/itcast/bbs/domain/Attachment.hbm.xml" />
<mapping resource="cn/itcast/bbs/domain/Role.hbm.xml" />
<mapping resource="cn/itcast/bbs/domain/SystemPrivilege.hbm.xml" />
<mapping resource="cn/itcast/bbs/domain/BlogLink.hbm.xml" />
<mapping resource="cn/itcast/bbs/domain/SystemLog.hbm.xml" />
</session-factory>
</hibernate-configuration>