Announcement Announcement Module
No announcement yet.
How to update parent without erasing child collections? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to update parent without erasing child collections?


    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?


  • #2
    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.


    • #3


      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.


      for exact details.


      • #4
        Interesting - thanks for pointing out your findings.