Results 1 to 7 of 7

Thread: How to use OpenSessionInViewFilter

Threaded View

  1. #1
    Join Date
    Oct 2005
    Posts
    7

    Default Problem when using OpenSessionInViewFilter !

    Hi everyone,

    I'm using the following frameworks for my web application:

    Hibernate 3.0.5
    Spring 1.2.5
    Struts 1.2.7
    Tomcat 5.0.28

    I tried to set up OpenInSessionViewFilter to access my persistent collections lazily in my views. Unfortunately, it seems i didn't configure my web.xml correctly as i always get this famous error :
    org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed



    This is how I configured my xml files:

    web.xml (sorry for the indentation)
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/application-context.xml</param-value>
    </context-param>
    <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.O penSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>*.do</url-pattern>
    </filter-mapping>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
    <param-name>debug</param-name>
    <param-value>3</param-value>
    </init-param>
    <init-param>
    <param-name>detail</param-name>
    <param-value>3</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>/welcome.jsp</welcome-file>
    </welcome-file-list>

    struts-config.xml
    <struts-config>
    <form-beans>
    ...
    </form-beans>

    <global-exceptions />

    <global-forwards>
    <forward name="portal" path="/index.jsp" />
    <forward name="loginPage" path="/login.jsp"/>
    </global-forwards>

    <action-mappings>
    <action path="/toModule" type="org.springframework.web.struts.DelegatingAct ionProxy" />

    <action path="/welcome" type="org.springframework.web.struts.DelegatingAct ionProxy" />
    ...
    </action-mappings>

    <controller processorClass="myApp.struts.main.RequestProcessor " />

    <message-resources parameter="myApp.struts.ApplicationResources" />


    <plug-in className="org.springframework.web.struts.ContextL oaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/application-context.xml" />
    </plug-in>
    </struts-config>

    application-context.xml
    <beans>

    <import resource="controller.xml" />
    <import resource="service.xml" />
    <import resource="dao.xml" />
    <import resource="persistence.xml" />
    </beans>

    i won't include all the xml as they are just mapping of beans. I'ill just focus on persistence.xml

    persistence.xml
    <beans>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean" singleton="true">
    <property name="dataSource">
    <ref local="dataSource" />
    </property>
    <property name="mappingResources">
    ...
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    <prop key="hibernate.show_sql">false</prop>
    </props>
    </property>
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>java:/comp/env/myDS</value>
    </property>
    </bean>
    </beans>

    It seems my hibernateFilter that i have defined just doesn't work because of a mistake in my configuration...


    Would you mind telling my what's wrong with my configuraion of OpenSessionInViewFilter ?
    Did I forget something ?


    Thank you in advance for your help.

    Best Regards,

    Jay
    Last edited by JayJayBee; Oct 29th, 2005 at 05:30 AM.

Posting Permissions

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