Re: Entries still appearing in the DataObject after deleting them in the database

From: Mike Kienenberger (mkienen..laska.net)
Date: Fri Feb 18 2005 - 10:58:34 EST

  • Next message: Mike Kienenberger: "Re: Derby support"

    Fredrik Liden <flide..ranslate.com> wrote:
    > At one time there are two items in an array of one dataObject.
    > Then going straight to the database I removed one item. Then when I
    > reload the page again I still see two items.

    Are you talking about removing the item externally to Cayenne?
    Or are you talking about using deleteObject() and still having the object
    show up in a to-many relationship?

    > I'm guessing the context is maintaining the state of the object and
    > because the context is stored in the session it's not being updated. Is
    > there any way to refresh a context to be aware of updates outside of the
    > framework? Or is this frowned upon? :)

    If you're talking about external updates, there's at least three different
    options:

    a) ignore the changes until they become important -- use optimistic locking
    to determine when you're trying to modify an externally-changed object.

    b) Change your external processes to use a cayenne-based notifier that sends
    update events.

    http://www.objectstyle.org/cayenne/userguide/design/events.html
    http://www.objectstyle.org/cayenne/modelerguide/configure-
    deployment/configure-cache.html

    c) set up a LAST_EXTERNAL_UPDATE table with a timestamp LAST_UPDATED field.
     Update the table after you externally change the data. Have your Cayenne
    app check this table periodically to see if LAST_UPDATED is newer than the
    last time you saw it. If so, update whatever you think changed.

    I'm currently using c) right now, but it's been tricky. I check for
    external updates in my web-based application at the start of every request.
     If it's changed, I invalidate all objects in my session DataContext,
    forcing them to reload. I have to use Level 1 caching because I don't want
    to invalidate objects actively being used in other sessions -- it'd be bad
    if an object someone was updating suddenly got invalidated and this is also
    why I only check for external updates at the start of a request.

    However, I want to have Level 2 caching so that an update in one session
    also updates the other sessions. What I did was set everything to use
    level 1 caching, but I set up a LocalEventBridge (LEB) and register one to
    every DataContext. This LEB listens for SnapshotChanged events and
    rebroadcasts them to other contexts. It still confuses me why this works
    -- I'm still not sure why this is different from Level 2 caching as I sit
    here and describe it. I guess I need to write some unit tests to gurantee
    that this all works the way I expect it to. Note that if you're trying to
    do something like this, Cayenne 1.1 has a bug in invalidation notification.
    Rather than setting the corresponding object in another DataContext as
    Hollow, forcing it to reload, it sets it as transient instead and removes it
    from the other context. This can cause some odd errors as objects suddenly
    appear to be "deleted." There's a patch in CAY-256 for 1.1RC1 as well as a
    fix installed in cvs.



    This archive was generated by hypermail 2.0.0 : Fri Feb 18 2005 - 10:58:00 EST