I've got a Hibernate object which's properties are all loaded lazy. Most of these properties are other Hibernate objects or PersistentSets.
Now I want to force Hibernate to eager load these properties for just one time.
Of course I could "touch" each of these properties with object.getSite().size()
but maybe there's another way to achieve my goal.
The documentation puts it like this:
References
This is an old question, but I also wanted to point out the static method
Hibernate.initialize
.Example usage:
The children are now initialized to be used even after the session is closed.
This is slow, because it makes a round trip for every item it needs to initialize, but it gets the job done.
According to the hibernate docs, you should be able to disable lazy property loading by setting the
lazy
attribute on your particular property mappings:For me this works:
Rather than this:
3 ways
1.HQL with left join children
2.SetFetchMode after createCriteria
3.Hibernate.initialize