-
1. Re: Correct way to load lazy collections in Seam
kragoth Mar 4, 2009 1:11 AM (in response to vk101)I don't really think that there is a 'correct' way of doing this.
But there are a number of options available and some are better then others when it comes to code maintainability etc.
My personal preference is that wherever you have your logic of looking up the entity, this is also where you load your collection. Either with HQL or Criteria.
It's very unlikely that you could develop an application bigger then a petshop app without writing some queries to fetch the appropriate object graph for you.
Letting SEAM's extended persistence context with Hibernate do all the work for you is not a good idea as you will end up executing much much more SQL then you should.Regardless of whether you are writing a SEAM(web) app or a Swing app you should always follow the principle of specifically loading the data you need for the page when you go to it. Not allowing some background/lazy initialization process to happen. If you let lazy initialization happen it abstract you away from what is actually going on in your application.
However, if you don't want to write queries etc then don't forget about hibernate's helper for initializing collections.
Hibernate.initialize(Entity.collection)