Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

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.

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

  • 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
    It's best to ask this question on the Spring Web forum (http://forum.springframework.org/forumdisplay.php?f=25).

    Comment

    Working...
    X