[hibernate-dev] Second-level cache and Inheritance

Sanne Grinovero sanne at hibernate.org
Mon Jul 18 07:03:54 EDT 2016


Hi Vlad,

I think that might be quite tricky to implement, as it might not
always be clear into which region we'd need to lookup from, or
invalidate, not least locks might need to cross multiple regions.
Think for example when a type A is removed with ID=1, and then a type
B with the same ID is being re-inserted as a replacement, but
"upgrading" the type, e.g. B extends A so it's similar to the original
value but adds some more fields.

Not that I'd ever recommend doing such weird things, but we obviously
need to be correct to deal with such scenarios.

If you then also throw in the fact that multiple such regions which
need to be treated correctly from a concurrency point of view, as a
combination of multiple different possible concurrency strategies,
then the code complexity explodes even further and there are many
details to take into account..
Assuming even that someone was up to the challenge to implement this
(and get it right?!), you'd pay a significant price in terms of
runtime performance due to this complexity.

-- Sanne





On 18 July 2016 at 11:10, Vlad Mihalcea <mihalcea.vlad at gmail.com> wrote:
> Hi,
>
> I bumped into this question on our forum:
>
> https://forum.hibernate.org/viewtopic.php?f=1&t=1043470
>
> And after I tried an example using the latest Hibernate version I see that,
> for inheritance, all subentities share the parent region name.
> This can  be found in org.hibernate.internal.CacheImpl
>
> final String cacheRegionName = cacheRegionPrefix +
> model.getRootClass().getCacheRegionName();
>
>
> As you can see, we take the rootClass when constructing the region name.
> For this reason, we cannot use different CacheConcurrencyStartegy with
> different subclass types.
>
> Is there any reason for this, or should we consider adding support for this
> feature?
>
> Vlad
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev


More information about the hibernate-dev mailing list