We're updating the issue view to help you get more done. 

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:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 IllegalArgumentException occurred while calling setter for property [org.hibernate.bugs.entities.Person.lazyAttribute (expected type = java.lang.String)]; target = [org.hibernate.bugs.entities.Person@44c79f32], property value = [<lazy>] at org.hibernate.property.access.spi.EnhancedSetterImpl.set(EnhancedSetterImpl.java:118) at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValue(AbstractEntityTuplizer.java:716) at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValue(AbstractEntityPersister.java:4701) at org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyProperty(AbstractEntityPersister.java:1175) at org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyPropertiesFromCache(AbstractEntityPersister.java:1158) at org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyProperty(AbstractEntityPersister.java:994) at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor$1.doWork(LazyAttributeLoadingInterceptor.java:105) at org.hibernate.bytecode.enhance.spi.interceptor.Helper.performWork(Helper.java:97) at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.loadAttribute(LazyAttributeLoadingInterceptor.java:76) at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.fetchAttribute(LazyAttributeLoadingInterceptor.java:72) at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.intercept(LazyAttributeLoadingInterceptor.java:61) at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.readObject(LazyAttributeLoadingInterceptor.java:296) at org.hibernate.bugs.entities.Person.$$_hibernate_read_lazyAttribute(Person.java) at org.hibernate.bugs.entities.Person.getLazyAttribute(Person.java:38) at org.hibernate.bugs.JPAUnitTestCase.loadPersonAndAccessLazyPropertyTx3(JPAUnitTestCase.java:89) at org.hibernate.bugs.JPAUnitTestCase.errorLoadingFromCacheWithLazyPropertyTest(JPAUnitTestCase.java:58) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.hibernate.property.access.spi.EnhancedSetterImpl.set(EnhancedSetterImpl.java:61) ... 40 more

Environment

None

Status

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

5.2.10
5.1.13
5.3.0.CR1

Priority

Major