hibernate如何配置二級緩衝

來源:互聯網
上載者:User

第一步:配置ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
 <diskStore path="java.io.tmpdir"/>
  <defaultCache
    maxElementsInMemory="10000" <!-- 緩衝最大數目 -->
   eternal="false" <!-- 緩衝是否持久 -->
   overflowToDisk="true" <!-- 是否儲存到磁碟,當系統當機時-->
    timeToIdleSeconds="300" <!-- 當緩衝閑置n秒後銷毀 -->
    timeToLiveSeconds="180" <!-- 當緩衝存活n秒後銷毀-->
   diskPersistent="false"
   diskExpiryThreadIntervalSeconds= "120"/>
</ehcache>

第二步:在hibernate.cfg.xml裡配置二級緩衝開啟以及供應商

<!-- 開啟二級緩衝,其實hibernate預設就是開啟的,這裡顯示的指定一下
        <property name="hibernate.cache.use_second_level_cache">true</property>
         指定二級緩衝產品的供應商
        <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> 
           -->

第三部:指定要使用二級緩衝的實體!

 <!-- 指定使用二級緩衝的實體
        <class-cache usage="read-only" class="com/com/colorme/legendarytree/model/LegendaryTreeBlessType"/>
        <class-cache usage="read-only" class="com/com/colorme/legendarytree/model/LegendaryTreeWaterType"/>
        <class-cache usage="read-only" class="com/com/colorme/legendarytree/model/LegendaryTreeStatus"/>
        <class-cache usage="read-only" class="com/com/colorme/legendarytree/model/LegendaryTreeType"/>
         -->

a.建立 JAVA_HOME
             C:/Program Files/Java/j2sdk1.5.0 (JDK的安裝路徑)
        b.建立 PATH
             %JAVA_HOME%/bin;%JAVA_HOME%/jre/bin
        c.建立 CLASSPATH
            .;%JAVA_HOME%/lib;%JAVA_HOME%/lib/tools.jar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.