posts - 431,  comments - 344,  trackbacks - 0
          你用正常方式定義你的 entity bean 類。JBoss EJB 3.0 將來的版本將支持 annotating entities 和所緩存的它們的關系的集合,但是現(xiàn)在你不得不直接配置底層的 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 的緩存區(qū)(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 類指定緩存區(qū)(cache region),這個類的所有實例將象上面定義的一樣緩存在/_default區(qū)里。EJB3 Query API 提供了讓你在指定的緩存區(qū)里保存或載入查詢結果(就是 entity beans 的集合)的方法。
          posted on 2008-06-13 11:55 周銳 閱讀(629) 評論(0)  編輯  收藏 所屬分類: EJBHibernate
          主站蜘蛛池模板: 巴里| 广东省| 新田县| 得荣县| 梁河县| 赤峰市| 马尔康县| 凤冈县| 宁远县| 海南省| 梁河县| 沐川县| 鄂州市| 兰西县| 通辽市| 类乌齐县| 德江县| 青岛市| 昔阳县| 冕宁县| 炎陵县| 乌兰浩特市| 城口县| 望奎县| 凤山县| 三河市| 资源县| 财经| 利津县| 津南区| 兰溪市| 自治县| 鄂托克前旗| 灵武市| 正定县| 霍林郭勒市| 政和县| 禹州市| 招远市| 奉贤区| 富裕县|