java如何查找数据是否正确_java-如何检查(调试)JPA查询是否从缓存或数据库获取结果...

我有简单的JPA查询

Query query = getEntityManager().createQuery("SELECT pn FROM ProductsNames pn"

+ " WHERE pn.languages = :language"

+ " ORDER BY pn.products.id ASC");

query.setParameter("language", language);

return query.getResultList();

如何检查这些方法的结果是否从缓存返回对象列表或直接从数据库返回对象列表?

在persistence.xml中,我设置了以下参数:

因此,在服务器的输出上,我可以监视执行的查询(但我不确定:如果查询在输出中可见,则表示查询已发送到数据库,或者查询已发送到entityManager,entityManager决定使用缓存和稍后将查询发送到数据库).

因此,我如何区分对象的结果是:

>直接从数据库

>直接从缓存

我将不胜感激.

解决方法:

因此,您可以多次执行查询并访问some cache statistics,例如查询命中高速缓存的次数:

Integer cacheHits = (Integer)((PerformanceMonitor)session.getProfiler())

.getOperationTimings()

.get(SessionProfiler.CacheHits);

如果您想在更复杂的场景中收集更多详细信息,PerformanceMonitor已经为您做到了:

The performance monitor will output a dump of cumulative statistics

every minute to the EclipseLink log.

The statics contains three sets of information:

Info: Statistics that are constant informational data, such as the

session name, or time of login.

Counter: Statistics that are cumulative counters of total operations, such as cache hits, or query executions.

Timer: Statistics that are cumulative measurements of total time (in nano seconds) for a specific type of operation, reading, writing, database operations. Statistics are generally grouped in total and also by query type, query class, and query name.

Counters and timers are generally recorded for the same operations, so

the time per operation could also be calculated.

标签:caching,jpa,eclipselink,java

来源: https://codeday.me/bug/20191118/2027874.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值