Inheritance and L2 cache

Description

Simple app works wrong with following entity structure

For first load or without cache everything works well

After loading of HolderEntity instance from cache, holdedEntity field initialised by object with type EntityBase (abstract class).

Pseudocode:

During loading from cache hibernate construct entity using special logic: for field it detect class type by variable type (it's EntityBase class) instead of discriminator (final Type[] types = subclassPersister.getPropertyTypes(); in DefaultLoadEventListener) and call method
SessionImpl.internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) witch "instantiate" abstract class and init fields by data from hibernate cache

It works same for lazy & eager loading of holdedEntity Class type stored in AbstractEntityPersister.EntityMetamodel. It looks like, field type for cache is static, but it's should depend on instance of field

How to solve it without disabling of hibernate L2 cache?

Test case https://github.com/demon101/hibernate-l2-inheritence
https://github.com/demon101/hibernate-l2-inheritence/blob/master/src/test/java/com/test/hibernate/L2InheritanceTest.java

Environment

None

Assignee

Christian Beikov

Reporter

ДмитрийН

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure