How to initialise collections of collections in Hibernate

hibernate, java, lazy-loading

Solution

Hibernate.initialize(parentList);

will just initialize objects in the list not association inside the list.

From the docs:

Note: This only ensures intialization of a proxy object or collection; it is not guaranteed that the elements INSIDE the collection will be initialized/materialized.

Edit: As per comment

Say if I had one `Student` Entity and every student Entity has a list of `Course` Entity. Then the student list can be initialized like this :

for (Student student : studentList) {
     Hibernate.initialize(student.getCourses());
}

Problem

I get a `util.List` of instances. each instance has its another collection. I want to initialize all instances of collections. Here is how do it. ``` Hibernate.initialize(parentList); ``` But when the session is closed. parentList's objects'properties can be retrieved. But its collection's instances's properties cannot be retrieved. The way I initialize is wrong or any other problem is there? or how to initialize all instances.?

Original source