Announcement Announcement Module
Collapse
No announcement yet.
OpenSessionInView and portlet support Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    The only difference to support hibernate 3 is...

    extend
    org.springframework.orm.hibernate3.support.OpenSes sionInViewInterceptor instead.

    So I suggest you create another package
    org.springframework.web.portlet.support.hibernate3

    and do the same sort of thing...

    Comment


    • #17
      Found another server it doesn't work in

      On Sun One Portal Server

      Code:
      if (request instanceof HttpServletRequest && 
                     response instanceof HttpServletResponse)
      is false...

      Comment


      • #18
        On WebLogic 8.1

        Code:
        if (request instanceof HttpServletRequest &&
                       response instanceof HttpServletResponse)
        is false...

        Comment


        • #19
          New Spring Portlet MVC Framework Update

          The latest update to the Spring Portlet MVC Framework has OpenSessionInViewInterceptor classes for both Hibernate 2 and Hibernate 3:

          http://opensource.atlassian.com/conf...ay/JSR168/Home

          Comment


          • #20
            Liferay

            Can anyone explain to me why this approach won't work with Liferay?

            Thx,
            Steve

            Comment


            • #21
              The new interceptors from June should work with Liferay just fine. It was the previous "hack" that would not work with Liferay.

              Comment


              • #22
                initDeferredClose w/o filter

                Hi,
                I had the same problem with lazy initiation and just used the function SessionFactoryUtils.initDeferredClose(sessionFacto ry) w/o defining any OpenSessionInView in web.xml and it works! But there is a question: what is the purpose of the filter: to close deferred existing session or something else? If the filter doesn't close the session , so how the session is terminated (in a right way or not)? I'm working with Vignette 7 portal and afraid that the session is managed in a wrong way.
                Thank you for response.

                Comment


                • #23
                  Take a look at the JavaDoc for the OpenSessionInViewFilter.

                  As you'll see, this filter (or interceptor) will ensure that there is a session bound to the thread for the entire processing of the request. The main advantage of this is that a first-level cache is shared by all the operations in your view, instead of having each data access operation use its own session and therefore its own cache.

                  You can actually tell this filter (or interceptor) to run in deferred close mode by setting the singleSession property to false. This is what you should be doing instead of calling SessionFactoryUtils.initDeferredClose yourself. Otherwise you also need to be calling SessionFactoryUtils.processDeferredClose when your request processing is complete. This is essentially what the filter (or interceptor) does when running w/ singleSession set to false.

                  So, regardless of if you want a single session or multiple sessions used, you should definitely use the filter (or interceptor) to make sure your sessions are closed properly at the end of your request processing.

                  Comment


                  • #24
                    Originally posted by johnalewis View Post
                    The new interceptors from June should work with Liferay just fine.
                    found this thread after a long time of struggling with osiv pattern and its implementation in liferay 5.2.3 with spring 3.0.
                    I can't figure out where should I attach the interceptor to be able to lazily load a list of objects from a .jsp that renders the VIEW mode of a portlet.

                    In my (view mode) controller I have a method that loads an object by id:
                    Code:
                    communication = communicationService.findById(c.getId());
                    and then returns a model and view like this:
                    Code:
                    return new ModelAndView("commmunication/details", l);
                    Then, in my dispatcher-servlet.xml I have a ViewResolver
                    Code:
                    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
                              p:prefix="/WEB-INF/jsp/"
                              p:suffix=".jsp" >
                              </bean>
                    that will call the /WEB-INF/jsp/commmunication/details.jsp expected, in which there is the call
                    Code:
                    <c:forEach items="${communication.questions}" var="question" >
                    that throws the exception:
                    Code:
                    ERROR [jsp:165] org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: it.*.Communication.questions, no session or session was closed
                    The problem is: since I have defined an Interceptor in my applicationContext.xml like this:
                    Code:
                    <bean name="openSessionInViewInterceptor"  class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
                            <property name="sessionFactory">
                                <ref bean="sessionFactoryAnnotation"/>
                            </property>
                            
                            <property name="singleSession" value="true"/>
                            <property name="flushModeName">
                                <value>FLUSH_AUTO</value>
                            </property>
                        </bean>
                    where should I put it as a property?

                    1) in my Controller defined in <controllerName>-portlet.xml;
                    2) in my dispatcher-servlet.xml (makes more sense);
                    3) ???

                    Comment


                    • #25
                      Exactly the same here.

                      I'm having the same environment as mox601. Additionally I found this snippet of code:

                      Code:
                      	<bean id="portletModeHandlerMapping"
                      		class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
                      		<property name="order" value="20" />
                      		<property name="portletModeMap">
                      			<map>
                      				<entry key="view">
                      					<ref bean="myController" />
                      				</entry>
                      			</map>
                      		</property>
                      		<property name="interceptors">
                      			<list>
                      				<ref bean="openSessionInViewInterceptor" />
                      			</list>
                      		</property>
                      	</bean>
                      Unfortunately, this doesn't work either

                      Code:
                      20:51:39,850 ERROR [jsp:165] org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.some.list.property, no session or session was closed
                      ...
                      Everything else is already said.

                      Comment


                      • #26
                        Interceptors have to be included in the HandlerMapping that ends up dispatching the request to it's specific controller. This is the same in both Portlet MVC and regular Web MVC.

                        Are you using Annotation-Based Controllers or the older Interface-based Controllers?

                        Comment


                        • #27
                          I'm using annotation-based controllers. It works for very simple queries within one table. The PortletModeHandlerMapping is (at least for the moment) the only Handler.

                          Comment


                          • #28
                            If you're using Annotation-Based Controllers, you shouldn't be using the PortletModeHandlerMapping -- it's for the Interface-Based Controllers. Actually you probably aren't really using it if your code is working -- it's probably just there and no requests are getting to it.

                            What you should be using (and probably are using) is the DefaultAnnotationHandlerMapping. It's probably declared in your context somewhere as a singleton. It handles all the handler mapping duties when using the standard annotations for mapping to controllers.

                            To use an interceptor with the DefaultAnnotationHandlerMapping, you just want to do something like:

                            Code:
                            <bean class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping">
                               <property name="interceptors">
                                   <bean class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"/>
                               </property>
                            </bean>
                            You can declare the beans separately and use IDs as well of course, but if you are only declaring these as singletons and only using them together, I think this works well.

                            Comment


                            • #29
                              At the moment I'm using the LocalSessionFactoryBean, not the annotation-driven one; my boss prefers this way. I didn't spend much time on the other possibilities, but annotations must be done in the POJOs, am I right? This would be very much spring code in the model layer.

                              Isn't it possible to use annotations only for the mapping and transaction part?

                              Ah, and before I forget: the mapping itself seems to work basically - the controller is called and presents me a *jsp (which is causing the error). Therefore I'm pretty like ->

                              I spent much time googling around about that topic; if you have some resources about this very special problem (spring, hibernate & transactions in portlets), let me know..I found many articles, but most of them cover servlet environments or are much too old.

                              Comment


                              • #30
                                Whoa -- back up. I think you misunderstood my question. Regarding annotations I was asking specifically about the controllers -- how are you creating your controllers in the MVC stack? Are they implementing on of the Controller interfaces, (which was the only choice in Spring 2.0)? Or are they using the new @Controller annotation plus other supporting annotations (which is the preferred choice in Spring 2.5+)?

                                Comment

                                Working...
                                X