Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

open session everywhere question

 
Matt Horton
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am rather rusty, and I have a hibernate question.

Imagine that I have the page-layout:


That is, foobarsearch.jsp collects search criteria, which are used to gather a list() of objects from a datastore, via hibernate. foobarlist.jsp displays these results in a table, in which a column displays a url, which calls the action foobar... leading to the display of the selected foobar in the foobar.jsp. The user can edit foobar and submit his/her changes, in which case it seems natural to return to the original list from his/her search.

My questions are naive, but voila:
1) Where would one begin and end a transaction or a session? I see repeated references to an open-session-in-view pattern, but this isn't immediately clear to me (?) since the table seems to render ok in the list jsp (and I can't keep a session open for the length of the user's edit).

2) in the foobar.jsp, is it more appropriate to edit the object from the resultset, or to call session.load(Foobar.class,foobarId)? I imagine that if I take the former route, I can
a.) call session.update(foobar), and
b.) if I modify the object in the list returned in the user's search, it will be much easier to return to the foobarlist.jsp, without having to keep the list in 'touch' (i.e. flagging something as dirty) with the database?

However, if I do not (reretrieve) the object in foobar.jsp (i.e. via load, or createCriteria().idEq(...)), I'm not sure how to handle the fetchmode, since the data that I display in the foobarlist.jsp are rather shallow. If I do call load to retrieve deeper associations, what is the proper pattern for displaying a (now) updated resultset when I return to the foobarlist.jsp? Is it inappropriate to resubmit the query?

Thank you for your patience.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically Open-Session In view is a pattern where you have a Servlet Filter open the session, begin the transaction, then pass on to the Servlet and JSP, then comes back to the filter to commit or rollback the transaction and close the session.

If in your Java code you already retrieve all the data you need for the JSP page, and do not lazy load that data, then you wouldn't need to use that pattern. But sometimes the pattern is a better approach.

Mark
 
Matt Horton
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark! I basically just needed (that) reassurance. I originally raised this question b/c I kept getting a ton of OutofMemoryException: PermGen errors, but it appears that that's an altogether separate issue.

With regards to the second point (fetchmode/page backs, etc.), I just created a bean to store the search criteria, and then resubmit that query after the edit. I wondered (above) whether or not that was bad-form, but it seems fine; I force the app to hit the db multiple times via pagination anyway.
[ March 01, 2007: Message edited by: Matt Horton ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic