Hi everybody,
Well i have a problem with the famous LazyInitializationException:
My webap uses struts + hibernate. When a request happens, a transaction begins, calls the DAOS and finally, i have a filter that commits and closes the hibernatesession. Then the JSP can't get de collection that i've got from hibernate:
1.- the action:
af = mapping.findForward(Constantes.FWD_USUARIO_AUTENTICADO);
List listaDepartamentos = gm.obtenerDepartamentosUsuario(user);
request.getSession().setAttribute(
Constantes.ATT_LISTA_DEPARTAMENTOS, listaDepartamentos);
***gm.obtenerDepartamentosUsuario calls a DAO, begins a transaction and gets the bean's collection.
2.- the filter
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
chain.doFilter(request, response);
HibernateUtil.commitTransaction();
} finally {
HibernateUtil.closeSession();
}
}
3.- The jsp:
<html:form action="/CargarDepartamento" target="herramientas" method="POST">
<html:select name="nombreDepartamento" property="nombreDepartamento"
onchange="cargarHerramientas()">
<html:option value="-1">[Selecciona un departamento]</html:option>
<html:optionsCollection name="listaDepartamentos"
label="nombreDepartamento" value="nombreDepartamento" />
</html:select>
<html:hidden name="departamentoForm"
property="accesoCargaDepartamento" value="sel" />
</html:form>
the html:select tries to get the different beans from the collection that i saved in the session (2.-)
The exception:
javax.servlet.jsp.JspException: Getter for property nombreDepartamento threw exception: org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
Any ideas???
Thank you very much!
|