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

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

    Comment


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

      Comment


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

        Comment

        Working...
        X