Accessing lazy basic property on entity loaded from 2nd level cache throws exception

Description

Basic description:
If an entity with a lazy basic attribute is loaded from the second level cache and the lazy attribute is accessed an exception is thrown. The reason seems to be that the cache entry for the entity attribute yields an instance of org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer.UNFETCHED_PROPERTY which is not handled. Due to the missing handling org.hibernate.persister.entity.AbstractEntityPersister goes ahead and tries to assign the field from it.

Maybe a duplicate/relative of which I was not able to determine given the specific environment/reproducer. This one is definitely reproducible on Version 5.2.10

Steps to reproduce:
1. Unzip attached reproducer which is derived from hibernate-test-case-templates/orm/hibernate-orm-5
2. Run "mvn clean verify"

Please note that as bytecode enhancement had to be enabled for test classes the pom.xml has been adapted.

Stacktrace:

Environment

None

Activity

Show:
Aaron Schmischke
April 4, 2018, 7:16 AM

Added a Patch (

) that should fix this issue including a test which should verify that.
Should also fix the initialization of basic attributes from the second level cache which is problematic as well as described in and

Gail Badner
April 18, 2018, 7:37 AM

, thanks for the test and patch! I added more checks to your test and uncovered another bug, and fixed that bug. Here is the pull request: https://github.com/hibernate/hibernate-orm/pull/2249

Aaron Schmischke
April 18, 2018, 8:06 AM

@Badner: Thanks for taking care of this and your improvements. I took a quick look and the improvements seem to be good.

Gail Badner
April 21, 2018, 12:43 AM

Thanks again for your help and for looking at the PR.

Fixed in master and 5.2 branches.

Gail Badner
May 8, 2018, 12:11 AM

Fixed in 5.1 branch as well.

Fixed

Assignee

Gail Badner

Reporter

Aaron Schmischke

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure