-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Problem with LazyInitializationException
PostPosted: Tue Nov 07, 2006 4:43 am 
Newbie

Joined: Mon Sep 25, 2006 7:04 am
Posts: 7
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!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 6:50 am 
Newbie

Joined: Tue Sep 05, 2006 10:39 am
Posts: 13
There could be a number of things. I'm tackling a similar issue myself.

Are you sure you have the Filter mapped to the request you are running?

Does the OpenSessionInViewFilter appear in the JSP stacktraces, down the bottom in amongst the servlet container classes?

Are you sure you are using a fresh object from the current HibSession? Perhaps it's an object from a previous request...

What version of Hibernate are you using?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 6:59 am 
Newbie

Joined: Mon Sep 25, 2006 7:04 am
Posts: 7
Hi,

I've mapped the filter in the web.xml of the Tomcat.

When the request arrives, it opens the session, begins a transaction, calls the bussiness and finally commits and closes.

The only thing i have to do is getting a collection of beans from hibernate (version 3) and put it into a html:select.

I have corrected it changing the table's hibernate config file: lazy="false". How could i use a lazy load for this case without having the exception?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 9:07 am 
Newbie

Joined: Tue Sep 05, 2006 10:39 am
Posts: 13
did you check the stacktrace of the exception for the filter?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.