Hibernate recursive initialization

alex_ber
Mar 9, 2021

--

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.

https://stackoverflow.com/a/11448224/1137529

The source code:

Code of ReflectionUtils:

--

--