Ok, now I think to have understood the problem:
Code:
message.getSender().getUserName()
and/or
message.getUser().getUserName()
is requiring data which has not been eager loaded, so hibernate tries to load this data and for this purpose it needs the session
which you already closed explicitly.
Quote:
How can I close this connection after page render?
This is the right question.
If you close the session after the page is rendered then you should get rid of the problem.
On the other side this question has nothing to do with hibernate and is off-topic here.
You should consult your jsp manual.
Or maybe it would be working with :
Code:
<%
boolean populateCurrentMessages = mm.populateCurrentMessages();
model.Message message = null;
int count = mm.getMessageList().size();
Iterator<model.Message> itr = mm.getMessageList().iterator();
while (itr.hasNext()) {
message = (model.Message) itr.next();
%>
<div class="message" id="message<%=message.getId()%>">
<p id="message-item">
<b><%=message.getSender().getUserName()%></b>
</p>
<p> <%=message.getUser().getUserName()%>
</p>
</div>
<%
mm.closeSession(); // you must implement this method by closing the session you used for making the query
}
%>