Re: Lazy Open Session In View with AOP
On Thu, May 7, 2009 at 8:53 AM, Christian Helmbold wrote: > > Thanks for your answer, James. > > I try to understand magic things. The missing peace in the puzzle was the > difference between Hibernates openSession() and getCurrentSession(). More > than one transaction within one session seems only to be possible with > openSession() and manual flushing and closing. > http://www.techfaq360.com/hibernate_interview_questions.jsp?qid=241 > > This is a pure Hibernate concern, but I want to post an important of the > answer to my initial question. > > The question "What is the current thread, the Hibernate Session is bound to, > in a Wicket application?" is still open. The current thread is the request thread. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
AW: Lazy Open Session In View with AOP
Thanks for your answer, James. I try to understand magic things. The missing peace in the puzzle was the difference between Hibernates openSession() and getCurrentSession(). More than one transaction within one session seems only to be possible with openSession() and manual flushing and closing. http://www.techfaq360.com/hibernate_interview_questions.jsp?qid=241 This is a pure Hibernate concern, but I want to post an important of the answer to my initial question. The question "What is the current thread, the Hibernate Session is bound to, in a Wicket application?" is still open. - Ursprüngliche Mail > Von: James Carman > An: users@wicket.apache.org > Gesendet: Mittwoch, den 6. Mai 2009, 22:13:09 Uhr > Betreff: Re: Lazy Open Session In View with AOP > > If you use the @Transactional annotation (or define your transactions > in the XML), Spring will take care of the transactions for you > automagically. Thanks, Christian - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Lazy Open Session In View with AOP
If you use the @Transactional annotation (or define your transactions in the XML), Spring will take care of the transactions for you automagically. On Wed, May 6, 2009 at 3:05 PM, Christian Helmbold wrote: > > Thanks for this hint. > > The Spring API doc says: > > "If set to "false", each data access operation or transaction will use its > own session (like without Open Session in View). Each of those sessions will > be registered for deferred close, though, actually processed at request > completion." > http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html#setSingleSession(boolean) > > I don't understand who sessions are opened with this setting. > > > > > - Ursprüngliche Mail >> Von: James Carman >> An: users@wicket.apache.org >> Gesendet: Mittwoch, den 6. Mai 2009, 20:34:27 Uhr >> Betreff: Re: Lazy Open Session In View with AOP >> >> You can try using the filter, just set the singleSession property to false. > > > > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
AW: Lazy Open Session In View with AOP
Thanks for this hint. The Spring API doc says: "If set to "false", each data access operation or transaction will use its own session (like without Open Session in View). Each of those sessions will be registered for deferred close, though, actually processed at request completion." http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html#setSingleSession(boolean) I don't understand who sessions are opened with this setting. - Ursprüngliche Mail > Von: James Carman > An: users@wicket.apache.org > Gesendet: Mittwoch, den 6. Mai 2009, 20:34:27 Uhr > Betreff: Re: Lazy Open Session In View with AOP > > You can try using the filter, just set the singleSession property to false. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
AW: Lazy Open Session In View with AOP
Thanks for your answer. I know the OpenSessionInViewFilterfrom Spring, but it opens a new Hibernate Session for every request even if you request an image. - Ursprüngliche Mail > Von: Carlo Camerino > An: users@wicket.apache.org > Gesendet: Mittwoch, den 6. Mai 2009, 20:33:44 Uhr > Betreff: Re: Lazy Open Session In View with AOP > > spring has implemented itw own opensessioninview filter., > i dont' think that you have to crete your own > > Spring has a class like this which you can declare in your web.xml > OpenSessionInViewFilter - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Lazy Open Session In View with AOP
You can try using the filter, just set the singleSession property to false. On Wed, May 6, 2009 at 2:29 PM, Christian Helmbold wrote: > > Hello, > > I want to use the Open Session In View Pattern with Wicket, but I don't want > to open a Hibernate Session for every request like the ServletFilter approach > does. > > I looked at the "lazy-loading Open Session in View" for JPA implementation > from Wille Faler. > http://faler.wordpress.com/2009/04/30/building-a-more-scalable-open-session-in-view/ > He uses AOP instead of a ServletFilter to intercept only those method calls > that need an EntityManager. > > My plan is to build something similar for Hibernate with Spring AOP. The > solutions would consist of the following steps: > > 1. An aspect creates a new Hibernate Session, if a method is called, that > needs one and none is already open. > 2. The transaction runs. > 3. The RequestCycle commits the transaction and closes the session. Or > rollback, if an exception was thrown. > > Is something wrong with it? > > The Hibernate Reference says: "When the transaction ends, either through > commit or roll back, the "current" Session is closed automatically." > https://www.hibernate.org/42.html#A6 > > This means that only one transaction can be executed in one request, right? > But what is, if I need more than one transaction per request? Since I have to > hold the session open during rendering, because of lazy loading, I cannot > commit a transaction if I don't know another Session will be opened > immediately and not to be closed until the end of the request cycle. > > Hibernate typically bounds the Session to the current thread. But was is the > current thread in a Wicket Application? Are those threads pooled? Could the > same session be used in two requests, when no commit happened? > > Thanks in advance, > Christian > > > > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Lazy Open Session In View with AOP
spring has implemented itw own opensessioninview filter., i dont' think that you have to crete your own Spring has a class like this which you can declare in your web.xml OpenSessionInViewFilter On Thu, May 7, 2009 at 2:29 AM, Christian Helmbold wrote: > > Hello, > > I want to use the Open Session In View Pattern with Wicket, but I don't want > to open a Hibernate Session for every request like the ServletFilter approach > does. > > I looked at the "lazy-loading Open Session in View" for JPA implementation > from Wille Faler. > http://faler.wordpress.com/2009/04/30/building-a-more-scalable-open-session-in-view/ > He uses AOP instead of a ServletFilter to intercept only those method calls > that need an EntityManager. > > My plan is to build something similar for Hibernate with Spring AOP. The > solutions would consist of the following steps: > > 1. An aspect creates a new Hibernate Session, if a method is called, that > needs one and none is already open. > 2. The transaction runs. > 3. The RequestCycle commits the transaction and closes the session. Or > rollback, if an exception was thrown. > > Is something wrong with it? > > The Hibernate Reference says: "When the transaction ends, either through > commit or roll back, the "current" Session is closed automatically." > https://www.hibernate.org/42.html#A6 > > This means that only one transaction can be executed in one request, right? > But what is, if I need more than one transaction per request? Since I have to > hold the session open during rendering, because of lazy loading, I cannot > commit a transaction if I don't know another Session will be opened > immediately and not to be closed until the end of the request cycle. > > Hibernate typically bounds the Session to the current thread. But was is the > current thread in a Wicket Application? Are those threads pooled? Could the > same session be used in two requests, when no commit happened? > > Thanks in advance, > Christian > > > > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Lazy Open Session In View with AOP
Hello, I want to use the Open Session In View Pattern with Wicket, but I don't want to open a Hibernate Session for every request like the ServletFilter approach does. I looked at the "lazy-loading Open Session in View" for JPA implementation from Wille Faler. http://faler.wordpress.com/2009/04/30/building-a-more-scalable-open-session-in-view/ He uses AOP instead of a ServletFilter to intercept only those method calls that need an EntityManager. My plan is to build something similar for Hibernate with Spring AOP. The solutions would consist of the following steps: 1. An aspect creates a new Hibernate Session, if a method is called, that needs one and none is already open. 2. The transaction runs. 3. The RequestCycle commits the transaction and closes the session. Or rollback, if an exception was thrown. Is something wrong with it? The Hibernate Reference says: "When the transaction ends, either through commit or roll back, the "current" Session is closed automatically." https://www.hibernate.org/42.html#A6 This means that only one transaction can be executed in one request, right? But what is, if I need more than one transaction per request? Since I have to hold the session open during rendering, because of lazy loading, I cannot commit a transaction if I don't know another Session will be opened immediately and not to be closed until the end of the request cycle. Hibernate typically bounds the Session to the current thread. But was is the current thread in a Wicket Application? Are those threads pooled? Could the same session be used in two requests, when no commit happened? Thanks in advance, Christian - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org