struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rahul Mohan <>
Subject Re: Struts2 Dynamic Merge of two webform objects / join two objects in database
Date Fri, 03 Sep 2010 12:11:57 GMT

I use the scope plugin ( for this. A bit 
heavy on the session memory, but suits my purpose.

Put @InOut annotation on your model with scope set as session. This 
outjects the object loaded from DB into session just before forwarding to 
the JSP. On submission, the object is injected back into the action class 
from session before the params interceptor is invoked, which will update 
the same object from http request. So, basically its the same object that 
gets updated. 

Hope this works for you.

- Rahul

"Robert Taylor" <>
"Struts Users Mailing List" <>
03-09-2010 17:01
Re: Struts2 Dynamic Merge of two webform objects / join two objects in 

Hi Nicolas,

I'ld also be interested in hearing about an elegant solution to this 
as well.

Ideally it would be nice if we all had nice simple models where we could 
reuse our hibernate
objects for both persistence and web binding. However, if have found, this 

is often not the case.

Although maybe not ideal, for the case you mentioned, i have always ended 
creating/using a separate DTO (data transfer object)
which contained a subset of the Hibernate entity object properties.

If the properties are simple enough, I have been able to use 
to transfer the appropriate values between the two objects.

Probably not the answer you were looking for, but this has been my 
so far.


----- Original Message ----- 
From: "Nicolas Kopp" <>
To: <>
Sent: Friday, September 03, 2010 5:23 AM
Subject: Struts2 Dynamic Merge of two webform objects / join two objects 

Hi there,

We (Team of two developers) use Hibernate integrated in a Struts2 web 
application. If we want to perform an update to our objects on the 
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 object's attributes 
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 
(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 

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

We are sure there must be other people out there facing similar problems 
even after quite some research efforts we were not be able to find 
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.
Thanks in advance!

Nicolas & Alex

To unsubscribe, e-mail:
For additional commands, e-mail:

Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message