3

When you run a JPQL update or delete query, is Hibernate smart enough to invalidate the 2nd-level cache for the entity that is changed?

Contrived example:

You have the JPQL:

update Product p set p.status = 'S' where p.name like 'Monitor%'

If you currently have products in the 2nd-level cache when that statement is run, will Hibernate invalidate all products from the cache or does it do nothing to the cache and the products in the 2nd level cache are now invalid?

Just FYI... I'm using JBoss 5.1 with Hibernate and JBossCache

larf311
  • 1,845
  • 3
  • 20
  • 24
  • Interesting. I think you can check that - set showSql=true (or if not using JPA, the hibernate property for showing the sql output on the console), and see if hibernate fetches again from the database an entity that was just updated with hql. – Bozho Jan 08 '10 at 06:52
  • That would only tell you if it reloaded those items into cache, which I don't imagine it does. What it wouldn't tell you is if it invalidated the cache so all instances of that entity would have to be reloaded from the database. I guess I'll just have to do a test and find out. I was hoping someone here would have a quick answer. – larf311 Jan 08 '10 at 17:14

1 Answers1

0

After running my own test and running across this bug it appears that it will invalidate the ENTIRE second-level cache, not just the second-level cache for any entities involved in the update.

larf311
  • 1,845
  • 3
  • 20
  • 24