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.  [ 4 posts ] 
Author Message
 Post subject: Partial updates with collections
PostPosted: Sun Apr 12, 2009 5:05 am 
Newbie

Joined: Sun Apr 12, 2009 4:43 am
Posts: 11
Hi,
I am thinking of doing the following but am not sure if it is a good idea because of collections.
Currently I have a JSF page which is created in HTTP request scope. When a data object is retrieved from Hibernate and used to set values on this page, only some of the data object's values may be used. Then, when the page is submitted, that subset of values is used to create a new data object with new values for saving to the database. Because it is request scope, some of the property values for the data object will then be null (because they were recreated from the page, which only displayed a subset of values)
Some questions:
a) what can be done to only update those values that have changed, rather than also overwriting unchanged columns with null values
b) am I going to run into trouble with this approach if it is perfectly valid to have null for some of the columns
c) what happens with collections with partial data stored - will it possibly be tricky to use equals/hashcode to decide if an element of the collection needs updating if some of the business key properties of the collection element are null
We could save unused fields as hidden on the Web page, but this could become unmaintainable. The reason for using request scope was to ensure we get fresh data from the database each time the user makes a request (and to avoid logic of deciding when to load blank data etc). But the more I think about it, the more I think the safest option is to keep the data object in HTTP session scope. Is this the usual route? I'd be interested to hear people's opinions/experience.
thanks, Baljeet


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 13, 2009 5:50 am 
Beginner
Beginner

Joined: Wed Sep 21, 2005 8:18 am
Posts: 31
Well my advice is that don't complicate the scenario unnecessarily. If your page/form does not contain too many fields, then pass those fields to backend. Retrieve save object from hibernation lazily and then set values of fields on page to retrieved object from hibernate and save & commit. object and save and commit again.

_________________
amer sohail


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 13, 2009 6:09 am 
Newbie

Joined: Sun Apr 12, 2009 4:43 am
Posts: 11
thanks, that was one option I had considered, except it would be potentially complicated if someone else had changed the same record/fields in the meantime as these would be overridden. I could also do a version check to avoid this though.
One question - why would I need to save and commit twice?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 13, 2009 6:23 am 
Beginner
Beginner

Joined: Wed Sep 21, 2005 8:18 am
Posts: 31
well save does not commit the changes permanently in database. you will have to commit transaction for permanent persistence.

_________________
amer sohail


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