Hi,
after reading tons of tutorial, books and messages in this forum, I still have a doubt.
In a web application implemented with Struts and Hibernate, what is the right way to implement a sequence of pages dealing with a master/detail object?
Suppose that the logic is more or less the following:
- in the form0 I find a field in which i can put the business key of the document; submission=action0
- in action0 I check if the business key already exists; if the key exists the object is retrieved from database and bound to httpsession; otherwise a new object is created (and bound to httpsession). forward to form1
- in form1 I can see the master (in an html form) and a summary of the detail (suppose this is an invoice; you could have a list of part number, quantity and price for every row).
To modify the master record I have a submit button who send the form fields to an action (action1) and to modify a single row I have to click on a hyperlink that open a form for the single row (containing more fields than those in the summary)
- action1 read the fields from the request and modify the object stored in httpsession
(same for modifications of row: only the object in httpsession is modified)
...
Obviously, after any insertion of rows I need to see that the summary of the detail contains the new row.
Same for modifications: if I change the price in a row, the summary should reflect this change.
Both in new object creation or in modification of an existing object, the operation of persisting to database has to occur ONLY when the user press a SAVE button ath the end of ALL insertions and modifications (after a flow of many html pages).
For this reason the saveOrUpdate method of Hibernate Session is called only at the end of the complete flow of html pages.
Now, suppose that an object is loaded from database for modification (remember that the object maps a master/detail document): I think the only way to implement a flow as described above if to force entire loading of object and related collections.
The option of using OpenSessionInView pattern with a ThreadLocal (to keep Hibernate Session until view rendering is complete) could avoid eager loading of all related collections, but every time I reconnect the session, the object in httpsession is synchronized with database.
Right?
Thank you
Delta
|