Announcement Announcement Module
Collapse
No announcement yet.
OpenSessionInViewFilter: Error 500: Filter [hibernateFilter] Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • OpenSessionInViewFilter: Error 500: Filter [hibernateFilter]

    im using:

    - Struts for the web context
    - Spring for the bussiness contex
    - Spring + Hiberante for the data access context

    im using ContextLoaderPlugIn to connect struts with spring

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

    my data access context is something like this:

    <!-- ********** Data Sources ********** -->

    <!-- VEPDS -->
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>java:comp/env/jdbc/vepds</value>
    </property>
    </bean>

    <!-- ********** Session Factory ********** -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="dataSource">
    <ref local="dataSource"/>
    </property>
    <property name="mappingResources">
    <list>
    <value>com\dsi\po\Address.hbm</value>
    <value>com\dsi\po\PersonPO.hbm</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.S QLServerDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    </props>
    </property>
    </bean>

    <!-- ********** Transaction Manager ********** -->

    <bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property>
    </bean>

    <!-- ********** Data Access Objects ********** -->

    <bean id="addressDAO" class="com.dsi.dao.AddressHibernateDao">
    <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property>
    </bean>

    my business context:

    <!-- ********** Bussiness Objects ********** -->
    <bean id="addressDAOProxy" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref bean="transactionManager"/>
    </property>
    <property name="target">
    <ref local="addressDAO"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>
    <bean id="addressService" class="com.dsi.bean.AddressServiceImpl">
    <property name="addressDao">
    <ref local="addressDAOProxy"/>
    </property>
    </bean>
    <!-- ********** Struts Objects ********** -->
    <bean name="/addaddress" class="com.dsi.action.InsertAddressAction" singleton="false">
    <property name="addressService">
    <ref local="addressService"/>
    </property>
    </bean>

    i configure the filter in web.xml

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/springconfig.xml</param-value>
    </context-param>
    <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate.support.Op enSessionInViewFilter</filter-class>
    <init-param>
    <param-name>singleSession</param-name>
    <param-value>true</param-value>
    </init-param>
    <init-param>
    <param-name>sessionFactoryBeanName</param-name>
    <param-value>sessionFactory</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>*.do</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    <!-- my InsertAddressAction.java >
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
    long addressId = 1L;
    Address address=addressService.getAddress(addressId);

    System.out.print("address.getPersonPOSet().size()= "+address.getPersonPOSet().size());
    mapping.findForward("");
    }

    but when i call a "addaddress.do" url that list a collection that is lazy loaded i get this error:

    Error 500: Filter [hibernateFilter]

    the stacktrace is:

    javax.servlet.ServletException: Failed to lazily initialize a collection - no session or session was closed
    org.apache.struts.action.RequestProcessor.processE xception(RequestProcessor.java:545)
    org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:486)
    org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:274)
    org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1482)
    org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:525)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:709)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    org.springframework.orm.hibernate.support.OpenSess ionInViewFilter.doFilterInternal(OpenSessionInView Filter.java:172)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)

    net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
    net.sf.hibernate.collection.PersistentCollection.i nitialize(PersistentCollection.java:209)
    net.sf.hibernate.collection.PersistentCollection.r ead(PersistentCollection.java:71)
    net.sf.hibernate.collection.Set.size(Set.java:106)
    com.dsi.action.InsertAddressAction.execute(InsertA ddressAction.java:70)
    org.springframework.web.struts.DelegatingActionPro xy.execute(DelegatingActionProxy.java:105)
    org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:484)
    org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:274)
    org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1482)
    org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:525)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:709)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    org.springframework.orm.hibernate.support.OpenSess ionInViewFilter.doFilterInternal(OpenSessionInView Filter.java:172)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)



    i have read all the post in the forum related to OpenSessionInViewFilter ... buy i dont know whats happening ....

    what am i doint wrong ???

    thanks for your help

    david

  • #2
    Check out this http://forum.springframework.org/showthread.php?t=14910 - apparently there is a problem when loading the Spring context inside struts.
    Last edited by robyn; May 16th, 2006, 04:35 AM.

    Comment

    Working...
    X