Results 1 to 4 of 4

Thread: How to update parent without erasing child collections?

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    2

    Default How to update parent without erasing child collections?

    Greetings,

    I'm using WebWork as a front-end to Spring/Hibernate along with the OpenSessionInViewFilter.

    The problem I'm having is that when saving the parent object on an HTML form, the child collections are deleted. When the view is rendered the form values are read from a persistent object in the ThreadLocal Session. When the form is submitted the updated values are bound to a new instance and merged with the existing one.

    This works fine, but any collections get wiped out because they are null in the newly instantiated parent object.

    Is there some way to indicate that a collection is simply unitialized rather than "empty"?
    Is there a way to do a merge() that ignores collections?
    Is there a way to initialize/reattach collections to a dirty parent object?

    I realize this is easy to fix by storing the updated request values in a transient object and copying them over one-by-one to the persistent object, but it seems like there should be a more elegant way for OSIV. Am I missing something obvious?

    Thanks!
    Ben

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    You can store the object in a temporary storage, disk or httpSession. You'll get the object from the HB session, store it to disk and then work with it.
    It's more or less like a long-transaction.
    You will read the object between request and work directly on it - the collections will be unitialized and HB will treat them as such.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Aug 2005
    Posts
    2

    Default SOLUTION

    thanks,

    I was hoping to avoid long transactions as there are complexities with transaction management and serialization of the object graph which I would rather avoid.

    I've dug around the Hibernate and WebWork forums and the best solution seems to be to modify the WebWork Interceptor stack so that the edit action binds the request parameters twice, with a prepare() in between. The first <params> binds the objects id, then prepare fetches a fresh copy of the object, then the second <params> re-binds the changed data over the initialized object.

    See: http://forums.opensymphony.com/threa...eID=4437&#4437

    for exact details.

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Interesting - thanks for pointing out your findings.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Similar Threads

  1. Saving Parent / Child Object Graph
    By matthewramella in forum Data
    Replies: 3
    Last Post: Nov 28th, 2007, 08:33 AM
  2. Replies: 1
    Last Post: Aug 18th, 2006, 11:04 PM
  3. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  4. Replies: 3
    Last Post: Jul 27th, 2005, 10:41 AM
  5. Replies: 0
    Last Post: Jun 6th, 2005, 10:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •