Lazy initialization is to boost performance. The problem is that it doesn't apply to all cases. In cases where you have to iterate over a list of objects and those have lazy loading properties that you need, it will generate a lot of extra queries to to database. In those cases it's best to use eager loading to fetch the properties. However, if you eager load too many properties, the queries will become slow because of the joins. So it's all about finding a good balance that fits you database schema. In order to find the balance monitor the amount of queries your actions make, and the time it took to execute the queries. In some simple database schemas OSIV can be avoided but with complex schemas this isn't always the case.
On 8/22/07, hezjing <[EMAIL PROTECTED]> wrote: > > This is something new to me, I always thought that lazy initialization > is to boost performance. So we should really use eager fetching by > default and minimize the use of OSIV. > > > On 8/22/07, Toni Lyytikäinen <[EMAIL PROTECTED]> wrote: > > "And, is there a better alternative than using > > OpenSessionInViewInterceptor?" > > > > Yes. It's important to realise that while OpenSessionInView feels very > > handy, it is not a particularly nice design pattern, as it can stress > your > > database with lots of small queries. It's best to learn how to do eager > > fetching with Hibernate and use it for most cases and rely on OSIV only > in > > some special cases where eager fetching is not possible. This way it's > often > > possible to build entire web applications without resorting to use OSIV. > > > > > -- > > Hez >