如何为JPA L2 Cache配置WIldfly Infinispan子系统?

qoefvg9y  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(105)

我正在尝试在Wildfly 14上启用JPA L2缓存。即使我添加了配置缓存也不会发生。日志显示正在缓存实体,但在检索它们时似乎没有使用该高速缓存。
我使用Hibernate作为JPA提供者,这些是我的配置。

  • standalon-ha.xml in wildfly.
<cache-container name="hibernate">
    <transport lock-timeout="60000"/>
    <local-cache name="local-query">
        <object-memory size="10000"/>
        <expiration max-idle="100000"/>
    </local-cache>
    <invalidation-cache name="entity">
        <transaction mode="NON_XA"/>
        <object-memory size="10000"/>
        <expiration max-idle="100000"/>
    </invalidation-cache>
    <replicated-cache name="timestamps"/>
</cache-container>

字符串

  • persistance.xml
<persistence-unit name="mysqlPersistenceUnit" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!--<exclude-unlisted-classes>false</exclude-unlisted-classes>-->
<shared-cache-mode>ALL</shared-cache-mode>
<jta-data-source>java:/DataSourceName</jta-data-source>
<properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    <property name="hibernate.archive.autodetection" value="class"/>
    <!--<property name="hibernate.show_sql" value="true"/>-->
    <!--<property name="hibernate.format_sql" value="true"/>-->
    <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
    <!-- cache -->
    <property name="hibernate.cache.use_second_level_cache" value="true" />
    <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/>
    <property name="hibernate.cache.use_query_cache" value="true" />
    <property name="hibernate.generate_statistics" value="true" />
    <property name="hibernate.cache.infinispan.statistics" value="true"/>
</properties>

  • 实体
@Entity
@Cacheable
@Table(name = "table_name")
public class EntityName implements Serializable { // }


这是我在执行数据库查询时从Hibernate得到的输出。每次我都能看到正在进行的数据库查询。

[org.hibernate.engine.internal.StatisticalLoggingSessionEventListener] (default task-1) Session Metrics {
664166 nanoseconds spent acquiring 2 JDBC connections;
125120 nanoseconds spent releasing 2 JDBC connections;
1002407 nanoseconds spent preparing 2 JDBC statements;
989037118 nanoseconds spent executing 2 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
1994332 nanoseconds spent performing 2 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
366780 nanoseconds spent executing 1 flushes (flushing a total of 2 entities and 0 collections);
201076 nanoseconds spent executing 2 partial-flushes (flushing a total of 1 entities and 1 collections)

b4wnujal

b4wnujal1#

在我的例子中,hibernate要求查询提示:

final EntityManager em = getEntityManager(); 
...
return em.createQuery(all).setHint("org.hibernate.cacheable", Boolean.TRUE).getResultList();

字符串

相关问题