0

Enviorment-

  1. Hibernate- query cache and 2nd level cache is enabled

  2. cache used- Ehcache with updatetimestampcache set to be eternal.

Problem- For a entity E, i have 2 rows in the table. So on query(to fetch all rows) via criteria with setcacheable(true), first time the 2nd level cache and query cache are populated.

Any further execution of the same query via criteria with setcacheable(true) is served from query cache. So far so good.

Problem- After a new object of entity E is saved using hibernate (no now there are 3 rows in table for entity E) ,via a transactional service layer method. Any Further query to fetch rows for entity E (with setcacheable(true)) returns only 2 objects. Where in it should return 3 objects.

It seems the query cache for Entity E is not in validated when a new entity is saved in its table.

Amit
  • 77
  • 3
  • Either: the update did not really happen/commit, or the update timestamps were not updated... What you can do to narrow down where the issue is would be to try a different 2LC provider, to see if the issue is with EhCache or Hibernate. You can try Infinispan (some examples in https://github.com/galderz/secondlc). Even for inserts, you can use READ_ONLY and avoid the need of JTA transactions. – Galder Zamarreño Jul 05 '13 at 09:45

1 Answers1

-1

SO This is what i think is the root cause, Its the way my application is using ehcahce. Details are as follows

  1. i have two separate application hosted in same tomcat.
  2. both of these application uses have a same jar(each application have a jar in its lib), which connects to the database and also loads the ehcache .

so clearly if app A does insert,it just invalidates its own ehcache. As the other application app B hosted in same tomcat,have its own ehcahe region, Application b will continue using the stale data.

Amit
  • 77
  • 3