Lazy associations – II

30 August 2008

Remember that hibernate does not support lazy initialization for detached objects.

Considering the problem with the code presented in the last post, we need to fix the problem. We need to move the code that reads from the collection to just before the transaction is committed. Also one can use a non-lazy collection or association, by specifying lazy=”false” for the association mapping. It is usually preferred that lazy initialization be used for almost all collections and associations.

Do remember that if you have too many non-lazy associations in your object model, Hibernate might end up needing to fetch the entire database into memory in every transaction, which is not at all required. We often want to choose join fetching, non-lazy by nature, instead of select fetching in a particular transaction.

Next few posts will shed light on how to customize the fetching strategy.

del.icio.us:Lazy associations – II  digg:Lazy associations – II  spurl:Lazy associations – II  wists:Lazy associations – II  simpy:Lazy associations – II  newsvine:Lazy associations – II  blinklist:Lazy associations – II  furl:Lazy associations – II  reddit:Lazy associations – II  fark:Lazy associations – II  blogmarks:Lazy associations – II  Y!:Lazy associations – II  smarking:Lazy associations – II  magnolia:Lazy associations – II  segnalo:Lazy associations – II  gifttagging:Lazy associations – II

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Lazy associations – II

Leave a Reply