Results 1 to 10 of 11

Thread: OpenSessionInView Interceptor doesn't work with Spring Webflow

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    3

    Default OpenSessionInView Interceptor doesn't work with Spring Webflow

    OpenSessionInView Interceptor works with Spring MVC and the Hibernate session is avlbl till the view is rendered.

    However, In my application I am using Spring MVC,Spring Webflow and Hibernate, the hibernate session closes before the view is rendered, hence we get Lazy Initialization exception.

    Do we have some other interceptor for this in Spring or we need to handle it manually.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Use the filter instead of the interceptor, if that doesn't work I suggest a read of Spring Web Flow and how to configure/use opensession in flow.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Dec 2011
    Posts
    3

    Default

    Thanks Marten !!..

    I configured OpenSessionInViewFilter and its working fine with with webflows (without any subflows ). In my application, there is a accountSearch.xml flow which has reference to a subflow accountDetails.xml. If app is configured this way, it gives

    java.lang.IllegalStateException: No value for key [org.hibernate.impl.SessionFactoryImpl@9f2588] bound to thread [http-8080-2]
    org.springframework.transaction.support.Transactio nSynchronizationManager.unbindResource(Transaction SynchronizationManager.java:199)
    org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter.doFilterInternal(OpenSessionInVie wFilter.java:206)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)


    But if I configured the accountDetails subflow in the accountSearch Webflow, (i.e I remove the subflow reference), the application
    works fine and does NOT give lazy initialization error.

    Request your help in this please !!!!

  4. #4
    Join Date
    May 2012
    Posts
    13

    Default

    well, try to use opensession in flow with annotating your webflow with <persistence-context/>. the session is kept open until the flow is finished. i would not recommend mixing opensession in view with spring webflow.

    i'm not sure if you can propagate an open session through a subflow and back. is your subflow requiring an open session. if yes then annotate it with persistence context and let spring manage your session while inside the flow.

  5. #5

    Default

    Open session in view is working for me with in SWF 2.3 with flows and subflows with the next configuration:

    <!-- Creates a flow executor in Spring, responsible for creating and executing flows -->
    <flow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
    <flow:flow-execution-listeners>
    <flow:listener ref="jpaFlowExecutionListener" />
    </flow:flow-execution-listeners>
    </flow:flow-executor>

    <!-- Listener for the JPA execution listener -->
    <bean id="jpaFlowExecutionListener" class="org.springframework.webflow.persistence.Jpa FlowExecutionListener">
    <constructor-arg ref="entityManagerFactory" />
    <constructor-arg ref="transactionManager" />
    </bean>

    <!-- Load flow definitions and make them available to the flow executor -->
    <flow:flow-registry id="flowRegistry">
    <flow:flow-location id="process-flow" path="/process/flows/process-flow.xml" />
    <flow:flow-location id="phase1-flow" path="/process/flows/phase1/phase1-flow.xml" />
    </flow:flow-registry>

    <!-- The FlowHandlerMapping helps DispatcherServlet to knowing that it should send flow requests to Spring Web Flow -->
    <bean class="org.springframework.webflow.mvc.servlet.Flo wHandlerMapping">
    <property name="flowRegistry" ref="flowRegistry" />
    </bean>

    <!-- The FlowHandlerAdapter is equivalent to a Spring MVC controller in that it handles requests coming in for a flow and processes those requests -->
    <bean class="org.springframework.webflow.mvc.servlet.Flo wHandlerAdapter">
    <property name="flowExecutor" ref="flowExecutor" />
    </bean>
    Then I use the tag
    <persistence-context />
    in every flow or subflow configuration XML. Nevertheless it is not working for standard Spring MVC controllers. Does anybody knows how to configure open session in view for working both flows and controllers?

    Regards.

  6. #6
    Join Date
    May 2012
    Posts
    13

    Default

    hm jpaFlowExecutionListener handles flows persistence. i think you should configure an extra interceptor.

    If you are using Hibernate you can configure it like this.

    https://community.jboss.org/wiki/OpenSessionInView

    To avoid mixing you flow calls and controller calls you should map it to your desired controllers to a specific path(url-pattern)...

    Code:
    <filter-mapping>
            <filter-name>HibernateFilter</filter-name>
            <url-pattern>/*</url-pattern> 
    </filter-mapping>
    Or you can use aop...like this
    https://community.jboss.org/wiki/SessionHandlingWithAOP

    Or..better use aop with spring, and bind it to the same transactionhandler...
    Last edited by emil1; Jul 27th, 2012 at 06:30 AM.

Tags for this Thread

Posting Permissions

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