0
votes

I have a application where the user needs to enter data but the form is spread across several screens each requiring the user to POST data to the server as the user change pages.

Normally, I would store a domain object in the session and have the user make changes to this object in the session. Once all user changes are complete I would then save all changes at once to the DB. This form is not a flow, the user can go to one page and back freely.

Using Grails, I want to know the best approach. This domain object is highly nested so creating a psudo-domain object for web layer (and then mapping field by field to the domain obj) is not an option.

I want to know if storing the Hibernate domain object in the session is a good idea? I am having Hibernate session issues however due to the domain object being detached from the hibernate session.

Very important: I cannot make saves to the database on each page change either. I can only save the domain object to the DB once the user has completed all their changes. As stated before, this could span several http requests. Each time, the user changes need to be temp stored somewhere.

I've tried several attempts to keep the domain obj in the session, then on each submit, reattach that domain object and make my updates, but grails flushes the session on each request so this causes incomplete domain objects to be saved.

I am hoping someone could lend me some advice on storing user changes in memory, then all at once, commiting changes to the DB.

Thanks

1

1 Answers

2
votes

You should be able to:

  1. Retrieve object graph by whatever means (entity query or get)
  2. Detach from hibernate session
  3. Store object graph in request.session
  4. Continue to modify object graph across multiple http requests
  5. Upon completion of your user edits, re-attach object graph to hibernate session (merge)
  6. Flush hibernate session and commit

Is this what you are doing? Hard to tell from your post if you want to keep your object graph in the hibernate session across requests, or you want to get it in the HttpSession across requests.