Results 1 to 2 of 2

Thread: Spring-portlet / Hibernate : use of OpenSessionInViewInterceptor for BOs lazy init

  1. #1
    Join Date
    Dec 2005
    Posts
    3

    Default Spring-portlet / Hibernate : use of OpenSessionInViewInterceptor for BOs lazy init

    Hi,

    I'm currently using Jetspeed and spring-portlet. I use a model layer which is handled by Spring and Hibernate : Services, DAOs and BOs. Services can open hibernate sessions to perform database requests. Portlet controllers call services to get the informations back. Everything works great except when I have to get a nested BO inside a BO in a controller.
    For example :
    IMyService myService = (IMyService) getService ("MyServiceName");
    IMyBO myBO = myService.getMyBO(someParameters);
    // At this point myBO is correctly instanciated and all fileds can be accessed.
    IMyOtherBO myOtherBO = myBO.getMyOtherBO();
    String info = myOtherBO.toString(); // Or .getAField()
    //throws a LazyInitializationException : could not initialize proxy - the owning Session was closed;

    So, I tried to configure my PortletModeParameterHandlerMapping with an OpenSessionInViewInterceptor to give myBO a session back.
    In my xml conf file (like books.xml) :
    <bean name="openSessionInViewInterceptor" class="org.springframework.web.portlet.support.hib ernate3.OpenSessionInViewInterceptor">
    <property name="sessionFactory"><ref bean="hibernateSessionFactory"/></property>
    </bean>

    <bean id="portletModeParameterHandlerMapping" class="org.springframework.web.portlet.handler.Por tletModeParameterHandlerMapping">
    <property name="interceptors">
    <list>
    <ref bean="parameterMappingInterceptor"/>
    <ref bean="openSessionInViewInterceptor"/>
    </list>
    </property>
    <property name="portletModeParameterMap">
    <map>
    <entry key="view">
    <map> ... All my entries views ...
    </map>
    </entry>
    </map>
    </property>
    </bean>

    A session is correctly initialized before the render or action call and is correctly closed after.
    The problem is that the CGLIBLazyInitializer proxy object of myBO doesn't use this session but still persists using the closed session.
    How can I force it to use the good session ?
    Is there another solution to my problem ?
    Note that the same code works great within servlets ("pure" spring) or within "pure" portlets application ie without using the spring-portlet layer.

    Thanks in advance,
    Romain

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    It's best to ask this question on the Spring Web forum (http://forum.springframework.org/forumdisplay.php?f=25).
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •