-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate-Struts2: Dynamic Merge of two webform objects
PostPosted: Fri Sep 03, 2010 5:34 am 
Newbie

Joined: Fri Sep 03, 2010 5:31 am
Posts: 2
We use Hibernate integrated in a Struts2 web application. If we want to perform an update to our objects on the database we fetch the data and load the resulting object into a web form where the user can edit the data. In this web form not all the objects attributes are displayed and editable. Submitting the form data will create a new object with the values set in the web form, which is then saved to the database again using Hibernate.
Since not all the attributes from this certain object were set in the web form, some values result as null, which leads us to the problem that these values (even though there are set in the DB) get overwritten with null values. Hibernate is set to dynamic-update=true in all involved mappings.

There are (at least) three workarounds that we could think of:

1. Adding the missing attributes as hidden fields in the web form (not very flexible)
2. Adding the missing attributes in the Java code before saving the object to the DB (not very flexible either)
3. Writing a utility class which merges the data from the persistent object with the one created by the web form (flexible but cumbersome).

What we do right now is to iterate through all methods, find out the getterMethods and setterMethods of both the "old" database-object and the "new" Hibernate object, compare values and take the values which are not null. This is not a very satisfying resolution, because some objects contain Other objects with values and so on, sometimes three or more layers of depth. Also, using reflection in Java is not a very nice resolution.

We are sure there must be other people out there facing similar problems but even after quite some research efforts we were not be able to find anything of help in the web.

We are even not sure if this is more a Hibernate or a Struts2 problem.

We'd be really grateful if someone could point us in the right direction. (Or Thread)
Thanks in advance!

Nicolas & Alex

Edit: We also posted this question in a struts-related forum here: http://www.coderanch.com/t/509027/Struts/Struts-Dynamic-Merge-two-webform because, as said, We are even not sure if this is more a Hibernate or a Struts2 problem. We're also on the struts user-mailing-list and I will post any resolutions form there in both forums.


Top
 Profile  
 
 Post subject: Re: Hibernate-Struts2: Dynamic Merge of two webform objects
PostPosted: Mon Sep 06, 2010 8:08 am 
Newbie

Joined: Fri Sep 03, 2010 5:31 am
Posts: 2
We solved the problem and found several solutions and picked one out. Deatiled description to be found here http://www.coderanch.com/t/509027/Struts/Struts-Dynamic-Merge-two-webform

we hope it helps someone else.

Cheers!


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