Support enabling caching at any level within a mapped hierarchy

Description

Historically Hibernate supports applying caching at the root-entity level. Even though we consider this the (extremely) best practice, JPA does define support for defining caching on specific subclasses, so we will need to add support for this.

Activity

Show:

Steve Ebersole December 14, 2017 at 5:49 PM

I think we can call this done for now.

Steve Ebersole December 13, 2017 at 3:15 AM

A few practical things to note in this change:

  • org.hibernate.mapping.PersistentClass#getCacheConcurrencyStrategy is no longer a proper way to check whether an entity is cached. org.hibernate.mapping.PersistentClass#isCached should be used instead. The reason being that we need to apply the @Cache values (explicit or implicit) to PersistentClass even if the root is not cached in case a subclass enables caching.

  • This also means that an entity is no longer cached just by calling org.hibernate.mapping.PersistentClass#setCacheConcurrencyStrategy. Instead org.hibernate.mapping.PersistentClass#isCached(true) should be called.

  • EntityPersister#hasCache has been deprecated and split in to EntityPersister#canReadFromCache and EntityPersister#canWriteToCache

Steve Ebersole December 12, 2017 at 9:18 PM

Another implication here... this effectively means a split in EntityPersister#hasCache to account for put and get separately:

  1. should put when the entity being persisted is cached

  2. should get when the entity or any of its subclasses is cached.

Steve Ebersole December 8, 2017 at 12:32 PM

The question is more about what we worked out in the new SPI in regards to what exactly will be put in the cache...

E.g. given a hierarchy such as:

Hibernate would report to you (via that org.hibernate.cache.cfg.spi.DomainDataRegionConfig contract) that all 3 are cached entities. Meaning DomainDataRegionConfig#getEntityCaching would report all 3 in the List. If you are fine with that, no problem.

Steve Ebersole December 7, 2017 at 3:21 PM

Just on 5.3. I will be moving that to master very soon. Early next week, if not sooner

Fixed

Details

Assignee

Reporter

Fix versions

Priority

Created December 5, 2017 at 3:11 PM
Updated January 18, 2018 at 4:00 AM
Resolved December 14, 2017 at 5:49 PM