Hibernate二級緩存的問題

本身摸索hibernate的二級緩存的問題先放出hibernate的二級緩存的配置的hibernate.cfg.xml同時還應該在src底下在配置ehcache.xml文件: java

<?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.url">
			jdbc:mysql://192.168.0.140:3306/wfnms
		</property>
		<property name="connection.username">wfnms</property>
		<property name="connection.password">wfnms</property>
		<property name="connection.driver_class">
			com.mysql.jdbc.Driver
		</property>
		<property name="myeclipse.connection.profile">Mysql</property>
		<property name="show_sql">true</property>
		<!-- 
		<mapping resource="com/hibernate/Test.hbm.xml" />
		 -->

		<!-- 開啓二級緩存 --> 
		<property name="hibernate.cache.use_second_level_cache">true</property> 
		
		<!-- 設置緩存提供者 --> 
		<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> 
		<mapping resource="com/hibernate/Test.hbm.xml"/>
		<!-- 指定緩存的類,和緩存的策略 -->
		<class-cache class="com.hibernate.Test" usage="read-only"/>
	
	</session-factory>

</hibernate-configuration>

 

ehcache.xml文件:
defaultCache標籤中的各屬性: mysql

maxElementsInMemory:能夠緩存的對象的最大數; sql

eternal:是不是永久緩存; 緩存

timeToIdleSeconds:指定緩存多久沒有被使用就清理掉; session

timeToLiveSeconds:指定緩存的生命長度; app

diskPersistent:指定緩存是否被持久化到硬盤中,保存的路徑由<diskStore/>指定 eclipse

<ehcache> 
<diskStore path="java.io.tmpdir"/> 
<defaultCache maxElementsInMemory="10000" 
eternal="false" overflowToDisk="true" timeToIdleSeconds="120" 
timeToLiveSeconds="120" diskPersistent="false"/>
</ehcache>
相關文章
相關標籤/搜索