Re: Weird Behaviour with Nullify rule

From: Jorge Sopena (jsopen..idsa.es)
Date: Thu Oct 21 2004 - 11:15:10 EDT

  • Next message: Mike Kienenberger: "Re: DB2 cached sequence numbers"

    Andrus Adamchik wrote:

    > On Oct 20, 2004, at 11:09 AM, Jorge Sopena wrote:
    >
    >> Mike,
    >>
    >> Both objects have the same database information. But the method
    >> hashCode() returns different result, so they are !equals() objects.
    >> How can Cayenne know where two objects are the same?
    >>
    >> Jorge
    >
    >
    > Jorge,
    >
    > Only now got a chance to scan through this thread... Could you post
    > the code that shows the problem? It will be easier to make
    > intelligent comments if I see the code ;-) A few points on the
    > questions raised in the thread:
    >
    > 1. Nullify rule: it affects the target behavior when the source is
    > deleted. So if "Company.listPaths" has a Nullify rule, it will
    > nullify path -> company pointer if the company is deleted, not the
    > other way around
    > (http://objectstyle.org/cayenne/modelerguide/modeling-object-layer/
    > delete-rules.html)
    >
    > 2. Cayenne ensures that there is at most one instance of each
    > DataObject in any given DataContext (so overriding "equals" is evil,
    > lets get to the core of the problem instead). So if it appears that
    > there are two objects that are the same, I guess one of them is
    > "transient", i.e. has DataContext set to null and is therefore != to
    > the one that has a non-null DataContext.
    >
    > So my advise would have been to set "path -> company" relationship
    > rule to nullify, still I am probably missing something, as you say
    > you delete Path3, and then you are able to fetch it again? I am
    > confused...
    >
    > Andrus
    >
    >
    >
    >
    Thanks Andrus,

    In relation to your questions:

    1- The Nullify rule is set to the relationship Path -> Company, and
    the relationship Company->listPaths has the rule Cascade. So, I think
    this is rigth.

    2- Both objects have their Persistent State to COMITTED, none of them
    is "transient".

    Here there is a fragment of my code where the problem happens:

         company.getListPaths() // Just to check the list . I get Path1 and
    Path2
        Path path = new Path() // Here I do, registerNewObject(this)
        path.setName("AAA");
        path.setCompany(company)
        db.commit(); // Here I do commitChanges()

    After that I create the answer to the client and

             company.getListPaths() return a List path1, path2 and path"AAA".

    Then the client do a request to delete the Path("AAA");

    I receive the PK for this path and search the object:
          Path path =
    (Path)DataObjectUtils.objectForPK(dataContext,Path.class,new Long(pk));
    //I see the query in the log
     
    Then I do,
             path.delete(); // Here I do, deleteObject(this)
        db.commit();

    The DB is correctly updated, but
    when I build the answer

      company.getListPaths() returns a List with path1, path2 and path"AAA".

    and none of them is transient.
    The Mike's solution is good, and solves the problem, but...

    Jorge



    This archive was generated by hypermail 2.0.0 : Thu Oct 21 2004 - 11:12:02 EDT