Hibernate主配置文件hibernate.cfg.cml详解

</pre><pre name="code" class="html"><!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 name="foo">
		<!-- 配置数据库信息 --> 
		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>   方言
		<property name="connection.url">jdbc:mysql:///hibernate_20120328</property>  <span style="font-family:Arial, Helvetica, sans-serif;">  <span style="white-space:pre">		</span>url</span>
		<property name="connection.driver_class">com.mysql.jdbc.Driver</property>   <span style="white-space:pre">	</span> 驱动
		<property name="connection.username">root</property><span style="white-space:pre">				</span>用户名
		<property name="hibernate.connection.password">root</property><span style="white-space:pre">			</span>密码

		<!-- 其他配置 -->
		<property name="hibernate.show_sql">true</property>   <span style="white-space:pre">				</span>现实sql语句
		<property name="hibernate.format_sql">false</property><span style="white-space:pre">				</span>格式化sql语句
		<!-- 
<span style="white-space:pre">			</span>自动建表
			create:先删除,再创建
			update:如果表不存在就创建,不一样就更新,一样就什么都不做。
			create-drop:初始化时创建表,SessionFactory执行close()时删除表。
			validate:验证表结构是否一致,如果不一致,就抛异常。
		 -->
		<property name="hbm2ddl.auto">update</property>
	
	
		<!-- 
			设置默认的事务隔离级别:
			隔离级别		对应的整数表示
			READ UNCOMMITED	1
			READ COMMITED	2
			REPEATABLE READ	4
			SERIALIZEABLE	8
		 -->
		<property name="connection.isolation">2</property>
		
		<!-- C3P0连接池设定-->
		<!-- 使用c3p0连接池  配置连接池提供的供应商-->
		<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider                                                                                                                                                     </property>
		<!--在连接池中可用的数据库连接的最少数目 -->
		<property name="c3p0.min_size">5</property>
		<!--在连接池中所有数据库连接的最大数目  -->
		<property name="c3p0.max_size">20</property>
		<!--设定数据库连接的过期时间,以秒为单位,
		如果连接池中的某个数据库连接处于空闲状态的时间超过了timeout时间,就会从连接池中清除 -->
		<property name="c3p0.timeout">120</property>
		 <!--每3000秒检查所有连接池中的空闲连接 以秒为单位-->
		<property name="c3p0.idle_test_period">3000</property>
		
	
		
		<!-- 使用二级缓存,默认是未打开的。 -->
		<!-- 指定要使用的缓存的提供商,这也就打开了二级缓存 
		<property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
		-->
		<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
		<!-- 开启使用查询缓存 -->
		<property name="cache.use_query_cache">true</property>
		<!-- 指定要使用二级缓存的实体类 -->
		<class-cache usage="read-write" class="cn.itcast.l_second_cache.Employee"/>
		<class-cache usage="read-write" class="cn.itcast.l_second_cache.Department"/>
		<collection-cache usage="read-write" collection="cn.itcast.l_second_cache.Department.employees"/>
	
		<!-- 导入映射文件 
		<mapping resource="cn/itcast/a_helloworld/User.hbm.xml"/>
		-->
	
	
	
	</session-factory>
</hibernate-configuration>



猜你喜欢

转载自blog.csdn.net/anyeshenshang1/article/details/51156184