NPE when Lazy loading collection without transaction for bytecode enhanced entitie

Description

When Lazy loaded collections are accessed outside a transaction for bytecode enhanced entities, a NullPointerException is thrown by org.hibernate.engine.internal.AbstractEntityEntry.overwriteLoadedStateCollectionValue().

This exception occurs when a Lazy Loaded collection is accessed outside a transaction, a temporary session is created to lazy load the collection and the loadedState of the EntityEntry for the PersistenceContext is set to null by;

org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.loadAttribute()

https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributeLoadingInterceptor.java#L88

This was introduced by

Environment

None

Status

Assignee

Gail Badner

Reporter

John O'Hara

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.0.9
5.2.1

Priority

Major
Configure