posts - 431,  comments - 344,  trackbacks - 0
          你用正常方式定義你的 entity bean 類。JBoss EJB 3.0 將來的版本將支持 annotating entities 和所緩存的它們的關系的集合,但是現在你不得不直接配置底層的 hibernate 引擎。讓我們看看通過可選的property元素配置 hibernate 緩存選項的persistence.xml文件。下面persistence.xml 里的定義緩存的元素應該被啟用:
          <!-- Clustered cache with TreeCache -->
          <property name="cache.provider_class">
          org.jboss.ejb3.entity.TreeCacheProviderHook
          </property>
           
          下面的屬性元素定義了所使用的緩存對象名和 MBean 名。
          <property name="treecache.mbean.object_name">
          jboss.cache:service=EJB3EntityTreeCache
          </property>
           
          下一步我們需要配置 entities 被緩存的內容。就像上面所展示的樣,缺省是什么都不緩存。我們使用@Cache 注解來標記需要緩存的 entity beans。
          @Entity
          @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
          public class Customer implements Serializable {
          // ... ...
          }
           
              一個簡單的原則就是,你應該對很少變動和頻繁使用的對象進行緩存.你可以在ejb3-entity-cache-service.xml配置文件里為每個 entity bean 微調緩存設置。例如,你可以指定緩存的大小。如果緩存里的對象太多,緩存有可能擠掉最老的對象(或者最少用的對象,依你的配置而定)來給新對象留出空間。mycompany.Customer entity bean 的緩存區(cache region)是/mycompany/Customer。
          <server>
          <mbean code="org.jboss.cache.TreeCache"
          name="jboss.cache:service=EJB3EntityTreeCache">
          <depends>jboss:service=Naming
          <depends>jboss:service=TransactionManager
          ... ...
          <attribute name="EvictionPolicyConfig">
          <config>
          <attribute name="wakeUpIntervalSeconds">5</attribute>
          <region name="/_default_">
          <attribute name="maxNodes">5000</attribute>
          <attribute name="timeToLiveSeconds">1000</attribute>
          </region>
          <region name="/mycompany/Customer">
          <attribute name="maxNodes">10</attribute>
          <attribute name="timeToLiveSeconds">5000</attribute>
          </region>
          ... ...
          </config>
          </attribute>
          </mbean>
          </server>
          如果你沒有為 entity bean 類指定緩存區(cache region),這個類的所有實例將象上面定義的一樣緩存在/_default區里。EJB3 Query API 提供了讓你在指定的緩存區里保存或載入查詢結果(就是 entity beans 的集合)的方法。
          posted on 2008-06-13 11:55 周銳 閱讀(629) 評論(0)  編輯  收藏 所屬分類: EJBHibernate
          主站蜘蛛池模板: 安龙县| 临洮县| 宁波市| 绵阳市| 平阴县| 宁强县| 裕民县| 项城市| 民乐县| 蛟河市| 土默特左旗| 平安县| 金塔县| 镇巴县| 丹寨县| 古浪县| 凯里市| 德格县| 大冶市| 砀山县| 北票市| 大荔县| 马尔康县| 怀来县| 邳州市| 鄂尔多斯市| 安福县| 九龙城区| 于田县| 永丰县| 称多县| 慈溪市| 六盘水市| 正镶白旗| 岑溪市| 雷州市| 文山县| 新闻| 建宁县| 大田县| 明溪县|