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

Natural Id 2nd level Cache not working when Identity is database generated

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

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

      Description

      When an entity has a database generated identity and an immutable natural identity, identity values are supposed to be cached in second level cache when configured.
      There seems to be a bug in public void org.hibernate.action.internal.AbstractEntityInsertAction.handleNaturalIdPostSaveNotifications(Serializable generatedId) method.
      It receives a valid generated Id value, but disregards it when calling PersistenceContext$NaturalIdHelper.manageSharedNaturalIdCrossReference(...). It passes getId() method result which evaluates to null.
      This causes null id value to be cached against the natural id value.
      Then, every time the entity is looked up by the natural id value, cache returns null. Identity is looked up in the database, but not cached, because cache access strategy (ReadWriteEhcacheNaturalIdRegionAccessStrategy) never updates cache entries (they supposed to immutable).
      In our system these lookups increase the database load dramatically.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: