Hi gurus, sorry if I ask again about lazy exceptions, but I read a lot of posts about, and still I didnt find the solution.
I have a DAO object that load an object and return it to the ActionForm.
In this action if I do: objH.getXXX() I get the lazy exception telling me that thw "owning" session is closed.
this is my DAO method:
Code:
public PersonalAlertH getPersonalAlertsByIDAlert(Integer idAlert)
{
PersonalAlertH pAlert=null;
Session hSession = factory.openSession();
try {
pAlert = (PersonalAlertH) hSession.load(PersonalAlertH.class,idAlert);
return pAlert;
} catch (HibernateException e) {
e.printStackTrace();
return null;
}finally{
hSession.flush();
hSession.close();
}
}
In my action I have this:
Code:
PersonalAlertH pH = myDAO.getPersonalAlertsByIDAlert(new Integer(alertID));
int id = ph.getAlertID(); //THIS THROWS THE LAZY EXCEPTION
I mean, is it possible that I cannot return a POJO load from the db, close the hSession, and return it to the action, without getting that error ????
One workaround I found is to clone the POJO setting into the new one data from the one loaded, and return the "cloned" one to the action.
Doing that I dont get the error.
Some explanation??
Thanks a lot
Max