PDA

View Full Version : OpenSessionInViewFilter: Error 500: Filter [hibernateFilter]


igalmarino
Aug 18th, 2004, 03:16 PM
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.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/presentationContext.xml, /WEB-INF/businessLogicContext.xml, /WEB-INF/dataAccessContext.xml" />
</plug-in>

my data access context is something like this:

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

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

<!-- ********** Session Factory ********** -->

<!-- VEPSF -->
<bean id="VEPSF" class="org.springframework.orm.hibernate.LocalSessionFact oryBean">
<property name="dataSource">
<ref local="VEPDS" />
</property>
<property name="mappingResources">
<list>
<value>cr/go/ice/vep/dao/hibernate/Caja.hbm.xml</value>
<value>cr/go/ice/vep/dao/hibernate/CuentaBancaria.hbm.xml</value>
<value>cr/go/ice/vep/dao/hibernate/EmisorTarjeta.hbm.xml</value>
<value>cr/go/ice/vep/dao/hibernate/Nota.hbm.xml</value>
<value>cr/go/ice/vep/dao/hibernate/Pago.hbm.xml</value>
<value>cr/go/ice/vep/dao/hibernate/Recaudador.hbm.xml</value>
<value>cr/go/ice/vep/dao/hibernate/Reversion.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
<!--
<prop key="hibernate.query.substitutions">true=1 false=0</prop>
-->
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

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

<!-- VEPTM -->
<bean id="VEPTM" class="org.springframework.orm.hibernate.HibernateTransac tionManager">
<property name="sessionFactory"><ref local="VEPSF"/></property>
</bean>

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

<!-- CajaDAO -->
<bean id="CajaDAO" class="cr.go.ice.vep.dao.hibernate.CajaDAOImpl">
<property name="sessionFactory">
<ref local="VEPSF" />
</property>
</bean>

my business context:

<!-- ********** Bussiness Objects ********** -->

<!-- CajaBO -->
<bean id="CajaBO" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager">
<ref bean="VEPTM" />
</property>
<property name="target">
<ref bean="CajaBOTarget" />
</property>
<property name="transactionAttributes">
<props>
<prop key="agregar*">PROPAGATION_REQUIRED</prop>
<prop key="modificar*">PROPAGATION_REQUIRED</prop>
<prop key="borrar*">PROPAGATION_REQUIRED</prop>
<prop key="obtener*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<bean id="CajaBOTarget" class="cr.go.ice.vep.bo.pojo.CajaBOImpl">
<property name="cajaDAO">
<ref bean="CajaDAO" />
</property>
</bean>

i configure the filter in web.xml

<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate.support.OpenSess ionInViewFilter</filter-class>
</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>

but when i call a jsp file that list a collection that is lazy loaded i get this error:

Error 500: Filter [hibernateFilter]

the stacktrace is:

[8/18/04 12:08:03:111 CST] 46e73abc OpenSessionIn I org.springframework.orm.hibernate.support.OpenSess ionInViewFilter Initializing filter 'hibernateFilter'
[8/18/04 12:08:03:221 CST] 46e73abc OpenSessionIn I org.springframework.orm.hibernate.support.OpenSess ionInViewFilter Filter 'hibernateFilter' configured successfully
[8/18/04 12:08:04:146 CST] 46e73abc WebGroup E SRVE0026E: [Servlet Error]-[Filter [hibernateFilter]: filter is unavailable.]: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
at org.springframework.web.context.support.WebApplica tionContextUtils.getRequiredWebApplicationContext( WebApplicationContextUtils.java:69)
at org.springframework.orm.hibernate.support.OpenSess ionInViewFilter.lookupSessionFactory(OpenSessionIn ViewFilter.java:186)
at org.springframework.orm.hibernate.support.OpenSess ionInViewFilter.doFilterInternal(OpenSessionInView Filter.java:150)
at org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:73)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapp er.doFilter(FilterInstanceWrapper.java:132)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.d oFilter(WebAppFilterChain.java:71)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispat cher.handleWebAppDispatch(WebAppRequestDispatcher. java:974)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispat cher.dispatch(WebAppRequestDispatcher.java:564)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispat cher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForwar d(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleIn vocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInv ocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcesso r.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDis patcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handle Request(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleReques t(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection. java:443)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.j ava:672)

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

Ignacio

irbouho
Aug 18th, 2004, 04:11 PM
8/18/04 12:08:04:146 CST] 46e73abc WebGroup E SRVE0026E: [Servlet Error]-[Filter [hibernateFilter]: filter is unavailable.]: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
at org.springframework.web.context.support.WebApplica tionContextUtils.getRequiredWebApplicationContext( WebApplicationContextUtils.java:69)
Your Filter fails because it can not extract the root WebApplicationContext since you did not configure one in your web.xml.

One thing you can do is to configure the root WebApplicationContext using ContextLoaderListener in your web.xml:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/businessLogicContext.xml /WEB-INF/dataAccessContext.xml
</param-value>
</context-param>

and configure your struts ContextLoaderPlugIn using only the presentation context

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

from spring javadoc

Struts 1.1 PlugIn that loads a Spring application context for the Struts ActionServlet. This context will automatically refer to the root WebApplicationContext (loaded by ContextLoaderListener/Servlet) as parent.

igalmarino
Aug 18th, 2004, 05:06 PM
Thanks ... i made this changes

web.xml

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/businessLogicContext.xml /WEB-INF/dataAccessContext.xml</param-value>
</context-param>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate.support.OpenSess ionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>VEPSF</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.ContextLoaderListe ner</listener-class>
</listener>

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

And everything works ok ...

i need to read more about the different context

thanks for the help
Ignacio

theone
Sep 10th, 2004, 10:19 PM
Can you show me the example code as how you actually add or update a record in the SimpleFormController?

I follow the instruction to configure web.xml, I use TransactionMananger

<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate.support.OpenSess ionInViewFilter</filter-class>
</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>


Here is what I have in the FormController:

protected Object formBackingObject(HttpServletRequest request)
throws ServletException {
EditUser editUser = new EditUser();
String userId = request.getParameter("id");

if ((userId != null) && !userId.equals("")) {
editUser.setUser(mgr.getUser(userId));
...
}
else {
User user = new User();
...
editUser.setUser(user);
}
}
/*** I ASSUME WHEN USER IS CREATED, A COLLECTION OF MEMBER IS ALSO CREATED TOO

This is what EditUser looks like:

public class EditUser {
private List roles = null;
private List titles = null;
private List inRoles = null;
private String title;
private User user;

/*** with getters and setters...

}

Member class is many-to-one to User Class

My problem is:
-when update editUser, Only User info gets updated, Member table does not get updated

-when delete a user, it works the way it should, user and related records in Member table get deleted

-when add a new user, i get
[9/10/04 22:01:06:281 EDT] 11028e1 UserFormContr I com.espn.web.UserFormController Saving : jklcom : jklcom
[9/10/04 22:01:06:312 EDT] 11028e1 DispatcherSer E org.springframework.web.servlet.DispatcherServlet Could not complete request
[9/10/04 22:01:06:328 EDT] 11028e1 DispatcherSer E org.springframework.web.servlet.DispatcherServlet TRAS0014I: The following exception was logged org.springframework.orm.hibernate.HibernateSystemE xception: could not reassociate uninitialized transient collection; nested exception is net.sf.hibernate.HibernateException: could not reassociate uninitialized transient collection
net.sf.hibernate.HibernateException: could not reassociate uninitialized transient collection

igalmarino
Sep 13th, 2004, 10:03 AM
im using Struts MVC not Spring MVC

Ignacio