Bytecode enhanced entities in a OneToMany relationship throws
org.hibernate.LazyInitializationException: Unable to perform requested lazy initialization [...] - no session and settings disallow loading outside the Session
when accessing the OneToMany collection when the child entity implements equals/hashcode that refers to the lazily loaded parent.
A test case will be attached. The test case works if the entities are not bytecode enhanced.
When lazily loading the child entities of the OneToMany relationship, the equals method on the child entity is called as when adding the children to the OneToMany set on the parent. The equals implementation refers the the parent which is lazily loaded as well. The problem though is that the child entity is not fully initialized and has not had the session linked into its LazyAttributeLoadingInterceptor - it's still null (see PojoEntityInstantiator.applyInterception). Therefore, the lazy load of the parent cannot be performed as there is no session and a LazyInitializationException is thrown from Helper.performWork.