熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

hibernate3二級緩存的配置及測試

2013-11-23 20:20:14  來源: Java開源技術 
配置ehcachexml文件放到classpath下
 <?xml version= encoding=GBK?>
      <ehcache>
             <diskStore path=D:\\TempObject/>
             <defaultCache
                       maxElementsInMemory=
                       eternal=false
                       timeToIdleSeconds=
                       timeToLiveSeconds=
                      overflowToDisk=true
              />
              <cache name=corebaseExampleForTest                                                                                    maxElementsInMemory=
                      eternal=false
                      timeToIdleSeconds=
                      timeToLiveSeconds=
                      overflowToDisk=true
               />
    </ehcache>

  建議自定義cache時cache名字和類路徑名相同
)不要使用默認緩存策略defaultCache(多個class共享)
)不要給cache name另外起名
否則繼承AbstractTransactionalDataSourceSpringContextTests做測試時拋出
orghibernatecacheCacheException: javalangIllegalStateException: The corebaseExampleForTest Cache is not alive(我注釋了紅色的cache使用defaultCache導致)

  在ExampleForTesthbmxml中添加(如果有集合也需要添加)
 <hibernatemapping>
    <class name=corebaseExampleForTest
        table=TESTTABLE lazy=false>
        <cache usage=readwrite/>
        <id name=id type=javalangString>
            <column name=id length= />
            <generator class=uuid></generator>
        </id>
        <property name=field type=javalangString />
        <property name=field type=javalangString />
    </class>
</hibernatemapping>

如果使用Annocation則類前添加
@Cache(usage = CacheConcurrencyStrategyREAD_WRITE)

From:http://tw.wingwit.com/Article/program/Java/ky/201311/28326.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.