aspose file tools
The moose likes Object Relational Mapping and the fly likes database update techniques? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "database update techniques?" Watch "database update techniques?" New topic
Author

database update techniques?

Allan Bond
Greenhorn

Joined: May 27, 2004
Posts: 7
Hello,

I'm using Hibernate as my persistence framework for a project. I'd like to start a discussion on best practices for performing updates.

Specifically, my problem is with retrieving data from html forms and then updating only those values that were modified by the user. For example, my Product update form (I'm using Struts BTW) may only display 5 of the 10 Product attributes. When the user submits the form, I can't just update the object in Hibernate because only 5 of the 10 attributes have values.

I need some way to merge the updated attributes with the attributes that exist in the database.

Here are the ideas I've had:

1) when updating in Hibernate, first reload the persistent version of the object, apply the changes from the web form and update

2) Store the original objects as retrieved from Hibernate in the session. After the web user submits the form, update the original objects in the session with the values from the web form.

3) send all 10 user object attributes to the form and hide the ones that shouldn't be updated using hidden inputs. When the form is submitted, all attributes will be present so that I can just update using Hibernate. (I realize there is danger here by allowing the web user to see things that perhaps they shouldn't)

What techniques have you used successfully?

Thanks,

Allan Bond
Sebastian Hennebrueder
Ranch Hand

Joined: Sep 09, 2004
Posts: 49
I would go for 1)
because you should keep your session small to make your application scalable and to have the option to cluster.
Second, messing around with hidden fields you do not need is error prone. You may forget one.

Just use the setter for fields you can input that's it. You might consider not to use your mapped class inside your formbean in this case but explicite fields.

Best Regards Sebastian


Things get always more complicated as expected.<br />Author of eBook Hibernate 3 Developer Guide by example<br />Tutorials about Hibernate, EJB, Struts, JSF <a href="http://www.laliluna.de" target="_blank" rel="nofollow">www.laliluna.de</a>
Allan Bond
Greenhorn

Joined: May 27, 2004
Posts: 7
Thanks for your input.

I actually tried #3 on a few forms and it turned out OK but only because I was allowing the user to update almost all of the attributes for a particular object.

However, in cases where the user is allowed to update only a few attributes, I will use approach #1 as you suggest.

Thanks!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: database update techniques?
 
Similar Threads
Update Single value in a row
Hibernate Updating a Object
Maintaining create/delete/update actions on child records in Hibernate across different sessions
In struts project , In one JSP page ,do new,edit,delete
Struts2 Dynamic Merge of two webform objects / join two objects in database