Hibernate: best practice to pull all lazy collections

VB_ picture VB_ · Nov 12, 2013 · Viewed 128.8k times · Source

What I have:

Answer

Prabhakaran Ramaswamy picture Prabhakaran Ramaswamy · Nov 12, 2013

Use Hibernate.initialize() within @Transactional to initialize lazy objects.

 start Transaction 
      Hibernate.initialize(entity.getAddresses());
      Hibernate.initialize(entity.getPersons());
 end Transaction 

Now out side of the Transaction you are able to get lazy objects.

entity.getAddresses().size();
entity.getPersons().size();