Hibernate recursive initialization

The question was how to write a function to recursively initialize all properties of object recursively so whole object graph is loaded in Hibernate.

From https://stackoverflow.com/questions/11445099/hibernate-recursive-initialization/25608383#25608383

You can use Hibernate.initialize() on the object to initialise it. I'm not sure if this cascades. Otherwise you could check instanceof HibernateProxy which gives you an isInitialised property.

Update: since initialize does not cascade you need to traverse the tree like you do already. Use a Hashset to keep track of objects you already processed.


The source code:

Code of ReflectionUtils: