struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Allen Lee <>
Subject Re: Struts2 Dynamic Merge of two webform objects / join two objects in database
Date Fri, 03 Sep 2010 19:14:46 GMT
We use the paramsPrepareParams stack for this (see for an example).
Basically the flow is: (1) params get applied first but the primary
use of this is to set the database entity ID that you want to update
(2) the prepare() method is invoked, this is where you load your model
object from the db with the entity ID from step 1 (3) params are
applied again, but this time they will be operating on your loaded
database entity, not a fresh instance.

On Fri, Sep 3, 2010 at 4:31 AM, Robert Taylor <> wrote:
> Hi Nicolas,
> I'ld also be interested in hearing about an elegant solution to this problem
> 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 up
> 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
> BeanUtils.copyProperties(....)
> to transfer the appropriate values between the two objects.
> Probably not the answer you were looking for, but this has been my approach
> so far.
> /robert
> ----- 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 in
> database
> 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 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 object's 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 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 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.
> Thanks in advance!
> Nicolas & Alex
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Allen Lee
Center for the Study of Institutional Diversity []
Arizona State University | P.O. Box 872402 | Tempe, Arizona 85287-2402
Office: 480.727.0401 | Fax: 480.965.7671

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

View raw message