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

From: Bryan Lewis (
Date: Tue Sep 07 2004 - 00:15:34 EDT

  • Next message: Andrus Adamchik: "Re: What means???"

    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.


    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 - 00:16:05 EDT