Announcement Announcement Module
Collapse
No announcement yet.
Issues with OpenSessionInViewFilter, Flex. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issues with OpenSessionInViewFilter, Flex.

    I am trying to upgrade from spring 2.5.6 to spring 3.0.5. I have my app running for a while now successfully with 2.5.6.

    During the filter chain execution the control reaches the OpenseesionInViewFilter and tries to bind the sessionFactory to TransactionSynchronizationManager.

    when the following piece of code is executed, the "hasResource" comes back with "false" and the else block is executed. (This code is from OpenSessionInViewFilter.doFilterInternal method).
    Code:
                    if (isSingleSession()) {
    			// single session mode
    			if (TransactionSynchronizationManager.hasResource(sessionFactory)) {
    				// Do not modify the Session: just set the participate flag.
    				participate = true;
    			}
    			else {
    				logger.debug("Opening single Hibernate Session in OpenSessionInViewFilter");
    				Session session = getSession(sessionFactory);
    				TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
    			}
    		}
    		else {
    			// deferred close mode
    			if (SessionFactoryUtils.isDeferredCloseActive(sessionFactory)) {
    				// Do not modify deferred close: just set the participate flag.
    				participate = true;
    			}
    			else {
    				SessionFactoryUtils.initDeferredClose(sessionFactory);
    			}
    		}
    But when it tries to bind the sessionFactory it fails with the exception

    java.lang.IllegalStateException: Already value [org.springframework.orm.hibernate3.SessionHolder@2 58e4566] for key [org.hibernate.impl.SessionFactoryImpl@38a22ea7] bound to thread [http-bio-9090-exec-10]
    at org.springframework.transaction.support.Transactio nSynchronizationManager.bindResource(TransactionSy nchronizationManager.java:179)
    at org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter.doFilterInternal(OpenSessionInVie wFilter.java:183)
    at org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)


    I am completely out of ideas, I am just trying to upgrade. Are there any changes to this filter in 3.0.5 that I need to apply in web.xml?

    Please, any help is appreciated.

    Thanks
    Srikanth

  • #2
    I am also noticing that the control is going into this filter twice per request. I couldn't figure out why? I removed the filter from my web.xml but I still see the control going in to this filter once. It's puzzling, what is different between 2.5.6 and 3.0.5?

    Comment


    • #3
      I have overrode the doFilterInternal method of the OpenSessionInViewFilter and got to working, but I don't think I need to this but I had to, to move forward. Here is the code (The file attachment didn't work for me).
      Code:
      /*
       * Copyright 2002-2009 the original author or authors. Licensed under the Apache License, Version
       * 2.0 (the "License"); you may not use this file except in compliance with the License. You may
       * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
       * applicable law or agreed to in writing, software distributed under the License is distributed on
       * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
       * the License for the specific language governing permissions and limitations under the License.
       */
      
      package com.workscape.spring.orm.hibernate3.support;
      
      import java.io.IOException;
      
      import javax.servlet.FilterChain;
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      import org.hibernate.Session;
      import org.hibernate.SessionFactory;
      import org.springframework.orm.hibernate3.SessionFactoryUtils;
      import org.springframework.orm.hibernate3.SessionHolder;
      import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;
      import org.springframework.transaction.support.TransactionSynchronizationManager;
      
      /**
       * An extention of {@link OpenSessionInViewFilter} to workaround the issue
       * https://jira.springsource.org/browse/SPR-8746.
       * 
       * @author Workscape, Inc.
       */
      public class WSOpenSessionInViewFilter extends OpenSessionInViewFilter {
      
          @Override
          protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                                          FilterChain filterChain) throws ServletException, IOException {
      
              SessionFactory sessionFactory = lookupSessionFactory(request);
              boolean participate = false;
      
              if(isSingleSession()) {
                  // single session mode
                  if(TransactionSynchronizationManager.hasResource(sessionFactory)) {
                      // Do not modify the Session: just set the participate flag.
                      participate = true;
                  } else {
                      logger.debug("Opening single Hibernate Session in OpenSessionInViewFilter");
                      Session session = getSession(sessionFactory);
                      SessionHolder sessionHolder = new SessionHolder(session);
      
                      if(TransactionSynchronizationManager.hasResource(sessionFactory)) {
                          // Do not modify the Session: just set the participate flag.
                          participate = true;
                          logger.warn("Participating in the existing session, after creating session holder");
                      } else {
                          TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder);
                      }
                  }
              } else {
                  // deferred close mode
                  if(SessionFactoryUtils.isDeferredCloseActive(sessionFactory)) {
                      // Do not modify deferred close: just set the participate flag.
                      participate = true;
                  } else {
                      SessionFactoryUtils.initDeferredClose(sessionFactory);
                  }
              }
      
              try {
                  filterChain.doFilter(request, response);
              }
      
              finally {
                  if(!participate) {
                      if(isSingleSession()) {
                          // single session mode
                          SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.unbindResource(sessionFactory);
                          logger.debug("Closing single Hibernate Session in OpenSessionInViewFilter");
                          closeSession(sessionHolder.getSession(), sessionFactory);
                      } else {
                          // deferred close mode
                          SessionFactoryUtils.processDeferredClose(sessionFactory);
                      }
                  }
              }
          }
      }
      After i used this filter its working but the control still goes twice in to this filter per request.

      I hope somebody can tell me what is going wrong with my upgrade.

      Thanks
      Srikanth

      Comment


      • #4
        is this forum dead? no new posts, no replies!!

        Comment


        • #5
          I just noticed your thread and had asked a question about lazy loading behaviour change and the use of OpenEntityManagerInViewFilter.

          What versions of Spring Flex/BlazeDS are you migrating to?

          Quite a few thing seems to have changed from earlier Spring Flex 1.0.3 to Spring Flex 1.5. I do not have an answer to your question but I am sure Jeremy will; I imagine he is busy with the Flex Roo integration.

          Spring Flex 1.0.3/BlazeDS 3 work fine with OpenEntityManagerInViewFilter and Spring 3.0.5.

          James

          Comment

          Working...
          X