Second level query cache invalidated when running a native update in Hibernate

Solution Verified - Updated -

Issue

Second level query cache invalidated when running a native update even if the update does not directly involve tables that are part of the cached query results.

  • Level 2 and query cache are enabled for a persistence unit.
  • Results for a query are marked cacheable:

            ... entityManager.createQuery("from Employee e", Employee.class).setHint("org.hibernate.cacheable", "true").getResultList();
    
  • A native update operation is executed:

            entityManager.createNativeQuery("delete from Other where name = 'Jane Smith'").executeUpdate();
    
  • Following the update, previously cached query results are no longer found in the cache and the log shows attempts to retrieve the query results from the database.

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7
  • Hibernate 5

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content