I am using @OneToMany relationship with FetchType.EAGER and getting result from a query as a stream. Then fetching eager collection after closing EntityManager, e.g.
@Entity
public class Basket {
...
@OneToMany(fetch = FetchType.EAGER, mappedBy = "basket")
private List<Fruit> fruits = new ArrayList<>();
...
Basket basket = entityManager.createQuery("SELECT b FROM Basket b", Basket.class)
.getResultStream()
.findFirst()
.get()
...
entitiManager.close();
...
basket.getFruits().size();
...
It fails with
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.hibernate.bugs.Basket.fruits, could not initialize proxy - no Session
It is broken since 5.4.4. Suspect is the code change in ScrollableResultsImpl class (rev cc01f2561dbca95bd58048f85e283ba1719ee588) |