Uploaded image for project: 'Hibernate ORM'
  1. HHH-4953

Inconsistent behavior when fetching cached subclass entities from 2L

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Out of Date
    • Affects Version/s: 3.2.5, 3.3.1, 3.5.0.Beta-1, 3.5.0-Beta-2, 3.5.0-Beta-3, 3.5.0-Beta-4, 3.5.0-CR-1, 3.5.0-CR-2
    • Fix Version/s: None
    • Component/s: None
    • Environment:
      Hibernate3.5.0CR2,HSQLDB, EHCache as 2L-cache Impl
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      Enabling the hibernate second-level cache is leading to inconsistent behavior when fetching cached subclass entities as opposed to fetching non-cached subclass entities.

      For more informations, please see
      https://forum.hibernate.org/viewtopic.php?f=1&t=1002880&p=2425931#p2425931

      Testcase attached.

      Cause:
      IMHO the bug consists in the fact, that
      persister.getRootEntityName() instead to persister.getEntityName() is passed as 3thrd parameter
      to the constructor of CacheKey in most places where CacheKey is used, for example in DefaultLoadEventListener.java:

      new CacheKey(
      event.getEntityId(),
      persister.getIdentifierType(),
      persister.getRootEntityName(),
      source.getEntityMode(),
      source.getFactory()

      In this way the real entity name get swallowed and the type-saveness is not guaranteed anymore.

      Workaround:

      Subclass2 tofind = null;
      try {
      tofind = (Subclass2) em.find(Subclass2.class,"identifier1");
      }
      catch (ClassCastException cc) {
      // swallow , this is a workaround
      }

        Attachments

          Issue links

            Activity

              People

              • Votes:
                5 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: