基于注解形式的hibernate二级缓存的使用(ehcache)

第三方插件为ehcache,spring+hibernate

基于注解形式;

我使用的是maven管理项目,需要添加的maven依赖:

    
        com.googlecode.ehcache-spring-annotations  
        ehcache-spring-annotations  
        1.1.2  
        jar  
        compile  
      

如果不使用依赖,直接导入包的话除了ehcache的jar包之外应该加上:common-logging,backport-util-concurrent这两个(我使用的是依赖,直接导入jar包方式没有尝试过,是看书上这么说的)

第一步:

package com.easitech.domain;

@Entity
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Table(name="tb_permission"
    ,catalog="crebas"
)
public class Permission  extends BaseDomain {
第二步:


			
			
				
					com.easitech.domain
				
			
	
			
				
					
					
						org.hibernate.cache.EhCacheProvider
					
					
					org.hibernate.dialect.MySQLDialect
					
					true
				
			
			
			
			
				
					nonstrict-read-write,fixedRegion
				
			
		
第三步:
在src下建立一个文件ehcache.xml;


    
             overflowToDisk="false" timeToIdleSeconds="0" timeToLiveSeconds="0"
        diskPersistent="false" diskExpiryThreadIntervalSeconds="120" />
         eternal="true" overflowToDisk="false"/>

这里注意timeToIdleSeconds中间一个是I一个是l,不一样的;一个是大写的i,一个是小写的L




你可能感兴趣的:(基于注解形式的hibernate二级缓存的使用(ehcache))