Hello Forum,
I would be grateful to hear from experienced people what is the correct approach is this case.
The standard situation that I have is following(for example):
I have two hibernate beans:
Code:
Language (id, description...)
Person (id, name, Set<Language> - 1..N relationship).
I'm going to show Person information edit dialog which contains the list of by user spoken languages.
Struts:
Code:
hibernateSession = openHibernateSession();
person = hibernateSession.find(id);
httpSession.setAttribute("EditedPerson", person);
hibernateSession.close()
JSP:
Code:
input type="text" value="${sessonScope.EditedPerson.name}"
....
forEach language from ${sessonScope.EditedPerson.languages} {
${language.description}
}
If I do this I'm getting IllegalStateException ot something like that - because the hibernateSession is closed.
So either I have to use some other instance(not those one that I get using "find"), something like
...
Code:
Person editedPerson = new EditedPerson();
editedPerson.setName(person.getName());
editedPerson.setLanguages(person.getLanguages());
...
httpSession.setAttribute("EditedPerson", editedPerson);
or I can put all the attributes(Set<Language> as well) in ActionForm that I use in Struts action and use it on JSP instead of http session attribute.
I found the example of struts and hibernate integration:
http://www.laliluna.de/struts-hibernate ... al-en.htmlThey have always one session object and they don't close it at all. So I have an abstract Action extended from all the others and doing following:
Code:
hibernateSession = servletContext.getAttribute("HibernateSession");
if (hibernateSession == null) {
hibernateSession = openHibernateSession();
servletContext.setAttribute("HibernateSession", hibernateSession);
}
...
abstractExecuteMethod(request, response, form... hibernateSession, servletContext)
or I save it in httpSession and have hibernateSession per httpSession.
But in both cases hibernateSession stays not closed!
What does that mean and what is the correct approach?
I hope I wxplained all not very complicated way.
Many thanks in advance.