Accessing a lazy collection in an enhanced class deletes it afterwards
Description
Attachments
Activity

Former user June 22, 2016 at 8:01 PM
Resolving after adding 5.0.10 as a fix version.

Former user June 22, 2016 at 8:00 PM
Reopen to add 5.0.10 as a fix version.

Former user June 2, 2016 at 3:31 AM
Fixed in master and 5.1.

Former user May 24, 2016 at 6:51 PM
, as it says in the pull request:
Running the test results in the following exceptiion:
java.lang.NoClassDefFoundError: org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteOneTestTask$Foo
at org.hibernate.test.bytecode.enhancement.lazy.HHH_10708.UnexpectedDeleteOneTestTask.getAnnotatedClasses(UnexpectedDeleteOneTestTask.java:32)
at org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask.prepare(AbstractEnhancerTestTask.java:30)
at org.hibernate.test.bytecode.enhancement.lazy.HHH_10708.UnexpectedDeleteOneTestTask.prepare(UnexpectedDeleteOneTestTask.java:39)
at org.hibernate.test.bytecode.enhancement.EnhancerTestUtils.runEnhancerTestTask(EnhancerTestUtils.java:98)
at org.hibernate.test.bytecode.enhancement.EnhancerTest.testLazyUnexpectedDelete(EnhancerTest.java:101)
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:497)
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.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:74)
Caused by: java.lang.ClassNotFoundException: org.hibernate.test.bytecode.enhancement.lazy.HHH_10708.UnexpectedDeleteOneTestTask$Foo not found
at org.hibernate.test.bytecode.enhancement.EnhancerTestUtils$1.loadClass(EnhancerTestUtils.java:160)
... 16 more
Caused by: org.hibernate.bytecode.enhance.spi.EnhancementException: Unable to enhance persistent attribute [org.hibernate.test.bytecode.enhancement.lazy.HHH_10708.UnexpectedDeleteOneTestTask$Foo:bars]
at org.hibernate.bytecode.enhance.internal.PersistentAttributesEnhancer.enhancePersistentAttribute(PersistentAttributesEnhancer.java:111)
at org.hibernate.bytecode.enhance.internal.PersistentAttributesEnhancer.enhance(PersistentAttributesEnhancer.java:61)
at org.hibernate.bytecode.enhance.internal.EntityEnhancer.enhance(EntityEnhancer.java:61)
at org.hibernate.bytecode.enhance.spi.Enhancer.enhance(Enhancer.java:143)
at org.hibernate.bytecode.enhance.spi.Enhancer.enhance(Enhancer.java:87)
at org.hibernate.test.bytecode.enhancement.EnhancerTestUtils$1.loadClass(EnhancerTestUtils.java:148)
... 16 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy30.targetEntity(Unknown Source)
at org.hibernate.bytecode.enhance.internal.PersistentAttributesHelper.getTargetEntityClass(PersistentAttributesHelper.java:266)
at org.hibernate.bytecode.enhance.internal.PersistentAttributesEnhancer.handleBiDirectionalAssociation(PersistentAttributesEnhancer.java:230)
at org.hibernate.bytecode.enhance.internal.PersistentAttributesEnhancer.generateFieldWriter(PersistentAttributesEnhancer.java:203)
at org.hibernate.bytecode.enhance.internal.PersistentAttributesEnhancer.enhancePersistentAttribute(PersistentAttributesEnhancer.java:102)
... 21 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.test.bytecode.enhancement.lazy.HHH_10708.UnexpectedDeleteOneTestTask.Bar
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at javassist.bytecode.annotation.MemberValue.loadClass(MemberValue.java:56)
at javassist.bytecode.annotation.ClassMemberValue.getValue(ClassMemberValue.java:89)
at javassist.bytecode.annotation.AnnotationImpl.invoke(AnnotationImpl.java:149)
... 26 more
Steve Ebersole May 24, 2016 at 1:21 PM
this is a pretty simple deviation in terms of backporting. What exactly do you need us to look at?
I'm trying to migrate from 4.3 to 5.1 using the new bytecode enhancer.
Given a class Foo with a collection of Bars with orphanRemoval=true, even just accessing the collection results in an exception:
A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: org.hibernate.test.bytecodeissue.Foo.bar
See attached test case.
The second test case shows the issue without orphanRemoval in an enhanced class: Bar has a @ManyToMany annotated Set of Foos that are lazy loaded. The test case shows the following output:
The collection is deleted after it was accessed in the log error statement.
The cases works fine in test case when I set doDirtyCheckingInline to false in the EnhancementTask - but in our live environment with far more complex classes, I can achieve the same behaviour with disabled doDirtyCheckingInline.
Everything works fine without bytecode enhancement.