I have simple JPA query
Query query = getEntityManager().createQuery("SELECT pn FROM ProductsNames pn"
+ " WHERE pn.languages = :language"
+ " ORDER BY pn.products.id ASC");
<property name="eclipselink.logging.level.sql" value="FINE"/>
You can enable the Performance Monitoring:
<property name="eclipselink.profiler" value="PerformanceMonitor"/>
So, you can execute your query many times you want and access some cache statistics, like the number of times that your query hit the cache:
Integer cacheHits = (Integer)((PerformanceMonitor)session.getProfiler()) .getOperationTimings() .get(SessionProfiler.CacheHits);
If you want collect more details in more complex scenarios, the PerformanceMonitor already do this for you:
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.