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.
You can use
Hibernate.initialize()on the object to initialise it. I'm not sure if this cascades. Otherwise you could check
instanceof HibernateProxywhich 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: