Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Second level cache does not work

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to make work hibernate second level caching not successfully.

I have:





persistence.xml


CategoryServiceImpl.java



and every time I call findAll() in CategoryService it calls data base, at least I see query log.

Is there some thing that I missed?
How to get caching work?

Thanks for any help.



 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only certain method hit the cache. From the documentation:


Whenever you pass an object to save(), update() or saveOrUpdate() and whenever you retrieve an object using load(), get(), list(), iterate() or scroll(), that object is added to the internal cache of the Session.


 
Alex Bokov
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found that caching works for single element

with session factory:
and with entity manager:

but does not work for lists

with session factory:
and entity manager:
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read Paul's post again.

Anytime you run a query whether from Criteria, HQL, or SQL Hibernate will NOT get data from the second level cache.

But if you turn on the second level query cache, then some queries can go to the query cache. In the query cache only IDs are stored. And there is a requirement that the Objects those IDs represent must be in the standard second level cache in a cache region.

One issue you have with the query cache is that the resultset could get stale real quickly if data is inserted or deleted from the database.

Mark
 
Alex Bokov
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
query caching is working

but hibernate need to be kicked

with session factory

with entity manager
 
reply
    Bookmark Topic Watch Topic
  • New Topic