Announcement Announcement Module
Collapse
No announcement yet.
OpenSessionInView and Transactions do not play well Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • OpenSessionInView and Transactions do not play well

    Hi All
    1. I use Hibernate, Spring and Struts with Tiles, Acegi, EhCache, WebSphere 6.0
    2. I am using OpenSessionInViewFilter for keeping my session open for a request
    3. I use org.springframework.orm.hibernate3.HibernateTransa ctionManager for the transaction manager
    I made sure I am not loading the same xml file into Spring so I am guessing I do not have muli session factory running around (If some one can tell me how to check it so I will know it it will be graite :>)
    All is working well as long as I do not access lazy collections after transaction
    After saving a record to the database I can not access lazy collection.
    The same code work before the transaction and fail after
    I read a lot of post around and could not find any that really helped me
    Anyone?

    Relevent spring config
    Code:
    	<bean id="HibernateTransactionManager"
    		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>
    	<bean id="ManagerTemplate"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
    		abstract="true">
    		<property name="transactionManager"
    			ref="HibernateTransactionManager" />
    		<property name="transactionAttributes">
    			<props>
    				<prop key="save*">PROPAGATION_REQUIRED</prop>
    				<prop key="set*">PROPAGATION_REQUIRED</prop>
    				<prop key="remove*">PROPAGATION_REQUIRED</prop>
    				<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    			</props>
    		</property>
    	</bean>
    This is Web.xml relevent def
    Code:
    <context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			/WEB-INF/applicationContext.xml,
    			/WEB-INF/applicationContext-acegi-security.xml
    			/WEB-INF/applicationContext-ajaxbeans.xml
    		</param-value>
    	</context-param>
    
    	<filter>
    		<filter-name>Open Session In View Filter</filter-name>
    		<filter-class>
    			org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    		</filter-class>
    		<!--init-param>
    			<param-name>singleSession</param-name>
    			<param-value>false</param-value>
    			</init-param-->
    
    	</filter>
    	<filter-mapping>
    		<filter-name>Open Session In View Filter</filter-name>
    		<url-pattern>/*</url-pattern>
    		<dispatcher>REQUEST</dispatcher>
    	</filter-mapping>
    
    	<filter>
    	<filter>
    		<description></description>
    		<display-name>Acegi Filter Chain Proxy</display-name>
    		<filter-name>Acegi Filter Chain Proxy</filter-name>
    		<filter-class>
    			org.acegisecurity.util.FilterToBeanProxy
    		</filter-class>
    		<init-param>
    			<param-name>targetClass</param-name>
    			<param-value>
    				org.acegisecurity.util.FilterChainProxy
    			</param-value>
    		</init-param>
    	</filter>
    	<filter-mapping>
    		<filter-name>Acegi Filter Chain Proxy</filter-name>
    		<url-pattern>/*</url-pattern>
    	</filter-mapping>
    	<listener>
    		<display-name>Spring context load listner</display-name>
    		<listener-class>
    			org.springframework.web.context.ContextLoaderListener
    		</listener-class>
    	</listener>
    	<listener>
    		<display-name>Spring request context loader</display-name>
    		<listener-class>
    			org.springframework.web.context.request.RequestContextListener
    		</listener-class>
    	</listener>
    And the struts config relevent def
    Code:
    	<!-- Spring plugin -->
    	<plug-in
    		className="org.springframework.web.struts.ContextLoaderPlugIn">
    		<set-property property="contextConfigLocation"
    			value="/WEB-INF/applicationContext-struts.xml" />
    	</plug-in>

  • #2
    Could you turn up the logging to DEBUG and post that?
    Last edited by karldmoore; Aug 27th, 2007, 03:54 PM.

    Comment


    • #3
      Debug log

      it was too long to post all log
      so I attached it
      as zip file
      I turned on the springframework debug and one class I wrote as Acegi filter
      if you need me to turn on Hibernate or Acegi debugging please tell me
      Thanks a lot

      Comment


      • #4
        I had a look through that but where's the actual exception?
        Last edited by karldmoore; Aug 27th, 2007, 03:54 PM.

        Comment


        • #5
          My bad

          here it is again
          I am sorry for wasting your time
          Nehemia

          Comment


          • #6
            The log says there's a NullPointerException, PurchaseRequestModelToDTO.java:23. What does that actually do? Is it possible to see that class and what line 23 does?
            Last edited by karldmoore; Aug 27th, 2007, 03:54 PM.

            Comment


            • #7
              PurchaseRequestModelToDTO

              Originally posted by karldmoore View Post
              The log says there's a NullPointerException, PurchaseRequestModelToDTO.java:23. What does that actually do? Is it possible to see that class and what line 23 does?
              Code:
              package il.co.cis.vms.manager.transformer;
              
              import il.co.cis.common.service.transformer.BaseModelToDTO;
              import il.co.cis.vms.m.model.PurchaseRequest;
              import il.co.cis.vms.manager.dto.PurchaseRequestDTO;
              
              /**
               * This class handle the transformetion of purchaseRequest model bean to dto
               * bean It also take care for project and study objects and not just the simple
               * properties It assume the object tree is present or there is long session
               * pattern for lazzy intiailization
               * 
               * @author <a href="mailto:[email protected]">Nehemia Litterat </a>
               *  
               */
              public class PurchaseRequestModelToDTO extends BaseModelToDTO {
              
                  /**
                   * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
                   */
                  public Object transform(Object model) {
                      PurchaseRequest purchaseRequest = (PurchaseRequest) model;
                      PurchaseRequestDTO result = (PurchaseRequestDTO) super.transform(model);
              //********** THE NEXT LINE IS WHERE THE CODE BREAKS*********
                      result.setProjectNovarId(purchaseRequest.getStudy().getProject().getId());
                      result.setProjectNovarName(purchaseRequest.getStudy().getProject().getName());
                      result.setStudyId(purchaseRequest.getStudy().getId());
                      result.setStudyName(purchaseRequest.getStudy().getName());
                      result.setPrUserId(purchaseRequest.getPrUser().getId());
                      result.setPrUserName(purchaseRequest.getPrUser().getName());
                      return result;
                  }
              }
              Thanks a lot for your efforts
              Nehemia

              Comment


              • #8
                Ok, so presumably the study or project is null. Extract the call into local variables and see which one is null. Just to try and track this down further.
                Last edited by karldmoore; Aug 27th, 2007, 03:53 PM.

                Comment


                • #9
                  I am trying to understand you

                  Originally posted by karldmoore View Post
                  Ok, so presumably the study or project is null. Extract the call into local variables and see which one is null. Just to try and track this down further.
                  I know the collection is null. This is my problem.
                  Usually this code works and the long session filter is doing its work
                  but when a transaction is taking place it breaks the connection with the session.
                  I suspect the transaction manager is closing the session
                  So after a transaction when I try to access these lazy properties I get the exception
                  I wanted to know if you know this problem or can you see if something in my configuration is wrong.
                  I thank you for your efforts

                  Comment


                  • #10
                    This might be the reason???

                    http://forum.springframework.org/sho...d.php?p=134526

                    Comment


                    • #11
                      Found solution

                      http://forum.springframework.org/showthread.php?t=39961
                      I think that might be something the template should take care for and not the DAO layer what do you think?

                      Comment

                      Working...
                      X