-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to handle an object living through several pages.
PostPosted: Thu Jun 25, 2009 11:06 am 
Newbie

Joined: Mon Oct 20, 2008 11:37 am
Posts: 7
Hello. This is a question about the best practice.
Problem: I am creating a web wizard that span over several pages. I have an object that is filled in while a user moves from one page to another. I do not want to store a partially filled in or partially modified object in a database. I want to retrieve it from the database after a user makes some selection on the first page, and save the result in the database after a user clicked "done" on the last page. What is the best way to achieve this?
Additional complications:
1. The object has a complex structure with references to other objects (one-to-one, one-to-many) with lazy initialization.
2. I use VMC schema with Velocity or JSP to display pages. This means that a servlet that processes a business logic saves the object in the HTTP request map and makes redirection to Velocity or JSP servlet where that object is used for creating a page.

Currently I open and close a hibernate transaction in a filter just before and after a servlet doPost method invocation, but this gives me a number of problems:
1. The session is closed at a moment the object is used for display, so lazy binding references cannot be resolved.
2. When moving from one page to another the object loses its hibernate session. Attempt to reconnect causes loosing all changes that where made in between.

In short: how to work with objects living through several pages?

Thank you,
Lev Tannen


Top
 Profile  
 
 Post subject: Re: How to handle an object living through several pages.
PostPosted: Thu Jun 25, 2009 6:31 pm 
Newbie

Joined: Thu Jun 25, 2009 3:45 am
Posts: 4
You could store the object in session. At the end of process, you will save the object.


Top
 Profile  
 
 Post subject: Re: How to handle an object living through several pages.
PostPosted: Fri Jun 26, 2009 12:18 pm 
Newbie

Joined: Mon Oct 20, 2008 11:37 am
Posts: 7
Thank you, for response, but this is not a complete answer. My question is actually of what could be a best practice to handle a Hibernate session for a multi-page wizard.
Currently my application opens a session every time it receives a request from a browser and closes it (with commit) when it sends a response. This actually means that an object is written to database every time when user moves from one page to another. This also means that an object become detached and needs reattachment on every request.

Another way to handle a hibernate session that I can think of is to store an open hibernate session in a HTTP session, and to keep it open until a user logs of or the HTTP session is expired. I am not sure that HTTP session has a hook that will allow me to do any actions upon its closing. Additional, but minor disadvantage of that scheme is that I have to commit or flush session explicitly, when a user finishes with a form, but may be this is actually an advantage.

Any other suggestions?

Thank you,
Lev Tannen


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.