栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用JPA2的@Cacheable而不是Hibernate的@Cache

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用JPA2的@Cacheable而不是Hibernate的@Cache

根据JPA 2.0规范,如果使用的需要有选择性的缓存实体

@Cacheable
注释,你应该到指定
<shared-cache-mode>
persistence.xml
(或同等
javax.persistence.sharedCache.mode

创建时
EntityManagerFactory
)。

下面是

persistence.xml
带有相关元素和属性的样本:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">  <persistence-unit name="FooPu" transaction-type="RESOURCE_LOCAL">    <provider>org.hibernate.ejb.HibernatePersistence</provider>    ...    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>    <properties>      ...      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.SingletonEhCacheProvider"/>      <property name="hibernate.cache.use_second_level_cache" value="true"/>      <property name="hibernate.cache.use_query_cache" value="true"/>    </properties>  </persistence-unit></persistence>

请注意,我已经看到至少一个与缓存有关的问题HHH-5303。因此,以上内容不能保证:)

参考文献

  • Hibernate EntityManager参考指南
    • 2.2.1包装
  • JPA 2.0规范
    • 第3.7.1节“共享缓存模式元素”
    • 第11.1.7节“可缓存的注释”


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/426510.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号