I use Hibernate 4.2, and I have a parent object that contains collections of child objects (one-to-many, the LAZY fetch type and annotated using @BatchSize(size=100)) .
If I request and load multiple parent objects and call access to this collection containing the child, hibernate uses @BatchSize as expected. But if I call the session, flush and then do the same thing, it initializes the collection only for that particular parent.
Is this the expected behavior of Hibernate?
Edit: sample
List parents = criteria.list ()
parents.get (0) .getXs (). get (0) // triggers loading Xs of all parents
vs
List parents = criteria.list ()
session.flush ()
parents.get (0) .getXs (). get (0) // triggers loading Xs of only the first parent
source share