Re: Configuring OpenSessionInViewInterceptor as S2's interceptor
In my experience, just having OSIV doesn't automatically imply that you expect all your data to be retrieved ad-hoc. (maybe the users do :) OSIV doesn't prevent the user from using eager fetching when necessary or useful ( and my experience delays it until your application is working and you're onto improving performance ). There's no reason I still can't Hibernate.initialize() or fetch join when I want to bring down the number of round-trips to the database. OSIV does provide a big boost ( to me, at least ) in being able to do rapid turn-around development. Toni Lyytikäinen wrote: > > 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 >> > > -- View this message in context: http://www.nabble.com/Configuring-OpenSessionInViewInterceptor-as-S2%27s-interceptor-tf4310239.html#a12278172 Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Configuring OpenSessionInViewInterceptor as S2's interceptor
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 >
Re: Configuring OpenSessionInViewInterceptor as S2's interceptor
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
Re: Configuring OpenSessionInViewInterceptor as S2's interceptor
"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.
Re: Configuring OpenSessionInViewInterceptor as S2's interceptor
probably you'll need to invert the filter-mapping declaration order. hezjing wrote: With OpenSessionInViewFilter, my web.xml will look like this struts2 org.apache.struts2.dispatcher.FilterDispatcher sessionFilter org.springframework.orm.hibernate3.support.OpenSessionInViewFilter struts2 /* sessionFilter /* Does it cause any conflict when both struts2 and sessionFilter are mapped to the same URL pattern? On 8/22/07, Toni Lyytikäinen <[EMAIL PROTECTED]> wrote: You can't use the OpenSessionInViewInterceptor from Spring in Struts 2. Struts 2 interceptors are not compatible with Spring interceptors as they have their own interface. You'll have to use OpenSessionInViewFilter. Take a look here: http://www.springframework.org/docs/api/org/springframework/orm/hibernate/support/OpenSessionInViewFilter.html On 8/22/07, hezjing <[EMAIL PROTECTED]> wrote: Hi I'm encountering this exception (when trying to iterate a list of orders for a specific customer in JSP), failed to lazily initialize a collection of role: com.dummy.Customer.orders, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException (AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected (AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.initialize( AbstractPersistentCollection.java:343) at org.hibernate.collection.AbstractPersistentCollection.read( AbstractPersistentCollection.java:86) at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249) at org.apache.struts2.util.MakeIterator.convert(MakeIterator.java:81) .. I'm using Struts 2, Hibernate and Spring (for creating actions, DAOs and etc). I read that Spring's OpenSessionInViewInterceptor will resolve this problem but can you describe how to configure OpenSessionInViewInterceptor in Struts2? And, is there a better alternative than using OpenSessionInViewInterceptor? -- Hez - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Roberto Nunnari Servizi Informatici SUPSI-DTI SUPSI-DTI - Via Cantonale - 6928 Manno - Switzerland email: mailto:[EMAIL PROTECTED] tel: +41-58-561 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Configuring OpenSessionInViewInterceptor as S2's interceptor
With OpenSessionInViewFilter, my web.xml will look like this struts2 org.apache.struts2.dispatcher.FilterDispatcher sessionFilter org.springframework.orm.hibernate3.support.OpenSessionInViewFilter struts2 /* sessionFilter /* Does it cause any conflict when both struts2 and sessionFilter are mapped to the same URL pattern? On 8/22/07, Toni Lyytikäinen <[EMAIL PROTECTED]> wrote: > You can't use the OpenSessionInViewInterceptor from Spring in Struts 2. > Struts 2 interceptors are not compatible with Spring interceptors as they > have their own interface. You'll have to use OpenSessionInViewFilter. Take a > look here: > > http://www.springframework.org/docs/api/org/springframework/orm/hibernate/support/OpenSessionInViewFilter.html > > > > On 8/22/07, hezjing <[EMAIL PROTECTED]> wrote: > > > > Hi > > > > I'm encountering this exception (when trying to iterate a list of > > orders for a specific customer in JSP), > > > > failed to lazily initialize a collection of role: > > com.dummy.Customer.orders, no session or session was closed > > at > > org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException > > (AbstractPersistentCollection.java:358) > > at > > org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected > > (AbstractPersistentCollection.java:350) > > at org.hibernate.collection.AbstractPersistentCollection.initialize( > > AbstractPersistentCollection.java:343) > > at org.hibernate.collection.AbstractPersistentCollection.read( > > AbstractPersistentCollection.java:86) > > at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249) > > at org.apache.struts2.util.MakeIterator.convert(MakeIterator.java:81) > > .. > > > > I'm using Struts 2, Hibernate and Spring (for creating actions, DAOs and > > etc). > > > > I read that Spring's OpenSessionInViewInterceptor will resolve this > > problem but can you describe how to configure > > OpenSessionInViewInterceptor in Struts2? > > > > And, is there a better alternative than using > > OpenSessionInViewInterceptor? > > > > > > > > -- > > > > Hez > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > -- Hez
Re: Configuring OpenSessionInViewInterceptor as S2's interceptor
You can't use the OpenSessionInViewInterceptor from Spring in Struts 2. Struts 2 interceptors are not compatible with Spring interceptors as they have their own interface. You'll have to use OpenSessionInViewFilter. Take a look here: http://www.springframework.org/docs/api/org/springframework/orm/hibernate/support/OpenSessionInViewFilter.html On 8/22/07, hezjing <[EMAIL PROTECTED]> wrote: > > Hi > > I'm encountering this exception (when trying to iterate a list of > orders for a specific customer in JSP), > > failed to lazily initialize a collection of role: > com.dummy.Customer.orders, no session or session was closed > at > org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException > (AbstractPersistentCollection.java:358) > at > org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected > (AbstractPersistentCollection.java:350) > at org.hibernate.collection.AbstractPersistentCollection.initialize( > AbstractPersistentCollection.java:343) > at org.hibernate.collection.AbstractPersistentCollection.read( > AbstractPersistentCollection.java:86) > at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249) > at org.apache.struts2.util.MakeIterator.convert(MakeIterator.java:81) > .. > > I'm using Struts 2, Hibernate and Spring (for creating actions, DAOs and > etc). > > I read that Spring's OpenSessionInViewInterceptor will resolve this > problem but can you describe how to configure > OpenSessionInViewInterceptor in Struts2? > > And, is there a better alternative than using > OpenSessionInViewInterceptor? > > > > -- > > Hez > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
Configuring OpenSessionInViewInterceptor as S2's interceptor
Hi I'm encountering this exception (when trying to iterate a list of orders for a specific customer in JSP), failed to lazily initialize a collection of role: com.dummy.Customer.orders, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86) at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249) at org.apache.struts2.util.MakeIterator.convert(MakeIterator.java:81) .. I'm using Struts 2, Hibernate and Spring (for creating actions, DAOs and etc). I read that Spring's OpenSessionInViewInterceptor will resolve this problem but can you describe how to configure OpenSessionInViewInterceptor in Struts2? And, is there a better alternative than using OpenSessionInViewInterceptor? -- Hez - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]