2010-04-24 48 views
4

我使用Hibernate 3.5.1,它與EHCache 1.5捆綁在一起。HIbernate 3.5.1 - 我可以放入EHCache 2.0.1嗎?

如果我想使用最新的EHCache版本(2.0.1),是否只是從我的項目中刪除ehcache-1.5.jar,並用ehcache-core-2.0.1.jar替換?任何需要注意的問題?

另外 - Hibernate映射文件中的緩存「區域」與ehcache配置xml中的緩存「名稱」相同嗎?我想要做的是定義2個命名緩存區域 - 一個用於只讀參考實體,不會改變(查找列表等),另一個用於所有其他實體。所以在ehcache中,我想定義兩個元素;

<cache name="readonly"> ... </cache> 
<cache name="mutable"> ... </cache> 

然後在我的Hibernate映射文件,我將指定緩存用於每個實體:

<hibernate-mapping> 
    <class name="lookuplist"> 
     <cache region="readonly" usage="read-only"/> 
     <property> ... </property> 
    </class> 
</hibernate-mapping> 

請問這項工作?一些文檔似乎暗示爲每個映射類創建了單獨的區域/緩存...

謝謝。

回答

2

如果我想使用最新版本的EHCache(2.0.1),是它只是一個從我的項目中移除了Ehcache-1.5.jar,並與ehcache的核心 - 2.0.1.jar更換的事?任何需要注意的問題?

根據有關使用的Ehcache作爲Hibernate Second Level Cache的Ecache文檔,你必須確實使用ehache-core.jar添加也改變Hibernate's configuration

另外 - Hibernate映射文件中的緩存「區域」與ehcache配置xml中的緩存「名稱」相同嗎?

是的。再次參考文檔,這在Configuring ehcache.xml中有解釋。

這會工作嗎?一些文件似乎暗示着一個單獨的區域/緩存獲取每個映射類創建

文檔並不意味着,它是寫黑白色在Cache mappings,這是默認的:

region (optional: defaults to the class or collection role name): specifies the 
name of the second level cache region 

它會工作嗎?技術上,是的。這是個好主意嗎?我不確定。國際海事組織最好在Hibernate和Ehcache級別都有更好的粒度區域(特別是如果你打算使用分佈式緩存和失效策略,你當然不想使所有實體無效)。我會使用Hibernate的默認值。

0

我有同樣的問題, 如果您使用的是maven。

它更好地防止休眠從本身下載ehcache並提供您的ehcache條目。

 <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate</artifactId> 
     <version>3.2.6.ga</version> 
     <exclusions> 
      <exclusion> 
       <groupId>net.sf.ehcache</groupId> 
       <artifactId>ehcache</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

這樣就不會下載內部的Ehcache在我的情況下,它是版本1.2.3

,然後把

 <dependency> 
     <groupId>net.sf</groupId> 
     <artifactId>ehcache-core</artifactId> 
     <version>2.4.2</version> 
    </dependency> 

在你的pom.xml

它應該工作。

相關問題