Re: 1-to-many relationships do not update on new query

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Sep 07 2004 - 10:11:31 EDT

  • Next message: Andrus Adamchik: "Re: Re[2]: Update DB Schema"

    BTW, for cross VM synchronization you may check "Remote Change
    Notifications" checkbox for the DataDomain (and configure JavaGroups
    settings via a corresponding dialog). But then if prefetching works
    well for you, remote notifications may be unneeded overhead.

    I am more worried about synchronization issues in the same VM mentioned
    by Bryan. I'll need to investigate the case of flattened relationships.

    Andrus

    On Sep 7, 2004, at 6:00 AM, Peter Backx wrote:
    > Sorry for the late reply, but I've been busy. Adding the "addPrefetch"
    > method to the query did solve the problem in my case.
    >
    > The DataContexts are in different JVMs so that might be the reason. I
    > don't think the problem exists within the same JVM. I'm not entirely
    > sure because I've recently changed the program to use one DataContext
    > bound to the thread. I don't remember any problems within one JVM
    > before that though. And the relationship is 2-way.
    >
    > Thanks a lot for the help,
    > Peter
    >
    >
    > Bryan Lewis wrote:
    >> I've come across the same behavior, I think. I have three Oracle
    >> tables, Employee, Role, and a join table EmployeeRole. Employee has a
    >> 1-to-many relationship "roles"; it's a flattened relationship
    >> Employee->Employee_Role and Employee_Role->Role.
    >> The first query for a list of employees works fine. I can see from
    >> the SQL logging that the employees are fetched and then each
    >> employee's roles are fetched.
    >> When the query is repeated, only the employees are refetched. If some
    >> other user session (in another browser -- same localhost-server JVM,
    >> different DataContext) has changed an employee's roles, the change is
    >> not seen in the first session.
    >> I tried adding query.addPrefetch("employeeRoles.role") but that
    >> didn't help. I tried invalidateObjects() and
    >> query.setRefreshingObjects(true).
    >> Other details:
    >> * There is a corresponding reverse relationship Role.employees.
    >> * A simpler 1-to-1 relationship didn't have any trouble.
    >> * I'm using version 1.1M6.
    >> HTH,
    >> Bryan
    >> Andrus Adamchik wrote:
    >>> Hi Peter,
    >>>
    >>> Does this happen in different DataContexts in the same JVM? Cayenne
    >>> should handle this case, but there is still some room for mistake
    >>> when automatic refresh can't be done properly. If you have any more
    >>> details on that, I'd appreciate it (e.g. is there
    >>> Object2.getObject1() relationship?).
    >>>
    >>> To explicitly deal with this problem you can use prefetching in the
    >>> query, e.g.:
    >>>
    >>> query.addPrefetch("object2s");
    >>>
    >>> Also, as far as cache policies are concerned, they are not related
    >>> to this case. Cache policies deal with caching *lists* of objects,
    >>> not the objects themselves.
    >>>
    >>> Andrus
    >>>
    >>>
    >>> On Sep 2, 2004, at 9:37 AM, Peter Backx wrote:
    >>>
    >>>> I'm currently using Cayenne (1.1B2) with MySQL for a 3 table
    >>>> database with a few relationships. The database itself is changed
    >>>> by different programs concurrently and when I try to update the
    >>>> view in one program it works ok for basic objects, however if
    >>>> objects were added to a 1-to-many relationship these don't seem to
    >>>> be updated.
    >>>>
    >>>> Maybe to make it more clear: I have Object1 that has a 1-to-many
    >>>> relationship with Object2. If I get Object1 through a query the
    >>>> first time everything works ok and Object1.getObject2s() works
    >>>> fine. However if new Object2's are added to that relationship (from
    >>>> another thread/program/DataContext) and I perform a new query to
    >>>> get Object1 I still get the old list of Object2's. So I don't see
    >>>> the newly added relationships.
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Sep 07 2004 - 10:11:37 EDT