Repeating database queries when accessing leaf class entities marked @Cacheable / @Cache in Hibernate

Solution Verified - Updated -

Issue

  • A class hierarchy includes an abstract entity not marked with @Cacheable or @Cache
  • Each time concrete leaf class entities marked with @Cacheable or @Cache are accessed, reload from the database occurs

    ... TRACE [org.hibernate.event.internal.DefaultLoadEventListener] ... Object not resolved in any cache: [support.hibernate.entity.FullTimeEmployee#John Smith]
    ... DEBUG [org.hibernate.SQL] ... select fulltimeem0_.name as name1_0_0_, fulltimeem0_1_.title as title2_0_0_, fulltimeem0_.planCode as planCode1_1_0_ from FullTimeEmployee fulltimeem0_ inner join Employee fulltimeem0_1_ on fulltimeem0_.name=fulltimeem0_1_.name where fulltimeem0_.name=?
    

Environment

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

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.