Re: forcing object update

From: Cris Daniluk (cris.danilu..mail.com)
Date: Wed Sep 28 2005 - 10:51:34 EDT

  • Next message: Andrus Adamchik: "Re: forcing object update"

    Basically, Cayenne provides add/remove methods for toMany
    relationships. However, I'm binding the relationship directly to the
    form with the framework (WebWork).

    So, with a multiselect, I might get this URL:

    cayenneObj.relationshipArray=1&cayenneObj.relationshipArray=2&cayenneObj.relationshipArray=3

    ... where 1, 2, 3 are PKs for Relationship objects. I have WebWork set
    to automatically convert these IDs to objects in the DataContext,
    which works beautifully. Then, it calls
    cayenneObj.setRelationship(List<Relationship> relationshipList).
    Actually, it calls it 3 times - once with a list of 1, once with a
    list of 2, once with 3.. an annoying "bug" that may have ruled out
    some cleaner solutions..

    So, what I've essentially done is created a setRelationship that
    stores the list and marks the object as modified. Then,
    validateOnInsert() reads the relationshipList and calls
    removeRelationshipArray / addRelationshipArray to resync the object to
    the list.

    It actually works quite well, though as I said, the snapshot doesn't
    get updated until AFTER the commit that never happens.

    Cris
    On 9/28/05, Andrus Adamchik <andru..bjectstyle.org> wrote:
    > Cris,
    >
    > Maybe I still need more coffee, but could you explain one more time
    > the initial problem you were trying to solve with the transient
    > property approach?
    >
    > Andrus
    >
    >
    > On Sep 28, 2005, at 9:31 AM, Cris Daniluk wrote:
    >
    > > I'm writing a small webapp that binds the objects directly to forms -
    > > for the most part, its working great, but I'm having a bit of trouble
    > > maintaining a many-to-many relationship across a flattened table with
    > > a multi-select box. Because the framework doesn't know a removed
    > > relationship from omitted data, and because it will happily readd the
    > > same one a thousand times, I had to hack around a little.
    > >
    > > Basically, I added a separate property in the wrapper object to store
    > > the list of related objects outside of Cayenne, move the persistence
    > > state to MODIFIED, and then use a validateOnInsert() method to re-sync
    > > the transient property with the Cayenne property. Unfortunately,
    > > Cayenne is outsmarting me - because the snapshots have not changed,
    > > commitChanges() reverts to COMMITTED.
    > >
    > > Is there a way I can force Cayenne to attempt to commit this object?
    > > Or, better, a native way to take a NEW list of objects in a
    > > relationship and have Cayenne decide what should be tossed and what
    > > should be kept...
    > >
    > > Thanks,
    > >
    > > Cris
    > >
    > >
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Sep 28 2005 - 10:51:38 EDT