Announcement Announcement Module

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions ( project, this forum has been decommissioned in favour of Spring Extensions one at:

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Costin Leau
SpringSource - Spring Training, Consulting, and Support - "From the Source"
See more
See less
Spring-portlet / Hibernate : use of OpenSessionInViewInterceptor for BOs lazy init Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

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


    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=" ernate3.OpenSessionInViewInterceptor">
    <property name="sessionFactory"><ref bean="hibernateSessionFactory"/></property>

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

    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,

  • #2
    It's best to ask this question on the Spring Web forum (