Accessing a lazy collection in an enhanced class deletes it afterwards

Description

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.

Environment

Hibernate 5.1.0

Assignee

Steve Ebersole

Reporter

Niko Wittenbeck

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Critical
Configure