Re: Weird Behaviour with Nullify rule

From: Mike Kienenberger (mkienen..laska.net)
Date: Tue Oct 19 2004 - 13:22:46 EDT

  • Next message: Hogue, Brian: "weird modeler startup error"

    > >Jorge Sopena <jsopen..idsa.es> wrote:
    > >>Recently I've found a strange behaviour when I delete a
    > >>CayenneDataObject who belongs to a toMany relationship.
    > >>I've got an object Company which has 1..n objects Path. In the modeler I

    > >>created a toMany relationship with delete rule = Nullify.
    > >>
    > >>Well,
    > >>At any moment, I do Company.getListPaths() and I get Path1 and Path2.
    > >>After I do a SelectQuery to recover Path1.
    > >>Then I delete Path1, and Company.getListPaths() only returns Path2, so
    > >>everything is right.
    > >>
    > >>But, in this other case the behaviuor isn't "correct" or as I expected.
    > >>I do Company.getListPaths() and I get Path1 and Path2.
    > >>After I create Path3 = new Path() and I do Path3.setCompany(Company).
    > >>Now the list Company.getListPaths() is Path1, Path2 and Path3.
    > >>After, I do a SelectQuery to recover Path3.
    > >>Then I delete Path3, but Company.getListPaths() has still Path1, Path2
    > >>and Path3.
    > >>
    > >>In the DB all the information is correct but in Cayenne the information
    > >>is inconsistent.
    > >>Debugging the system I've realised that Cayenne try to find the new
    > >>Path3 in the list but it doesn't find it.
    > >>For the system the Path3 recovered by the SelectQuery isn't equals() the

    > >>Path3 is in the list.
    > >>
    > >>Why happens this? Why are different Objects in case 2 and equals Objects

    > >>in case 1?

    > Mike Kienenberger wrote:
    > >After this code,
    > >
    > >Path3 = new Path();
    > >Path3.setCompany(Company);
    > >
    > >Did you do a
    > >
    > >dataContext.commitChanges();

    Jorge Sopena <jsopen..idsa.es> wrote:
    > Yes, of course.
    > I forgot writing it down.

    I thought so too since you said the database was correct, but I figured I'd
    ask just to be sure.

    I'm no expert in this area, but have you tried looking at the sql log from
    the point where you delete path3 to the point where you call
    Company.getListPaths()?

    If Company.getListPaths() is not re-executing the query (generating an SQL
    query to the database), that could explain the problem. You'd have removed
    path3 from the database with the delete, but the list itself might still
    contain a path3 object with PersistentState.TRANSIENT. (Meaning the object
    has been deleted.).

    If you are using 1.1RC1, and you try to do a path3.resolveFault() [using the
    path3 object from the Company.getListPaths()], what happens? If the above
    situation is the case, you should then get a CayenneRuntimeException()
    stating "Error resolving fault, no matching row exists in the database for
    ObjectId." This means that your list contains a deleted item that no
    longer exists in the database.

    The correct behavior might be to invalidate Company right after deleting
    Path3 to force it to refetch the data in "getListPaths()"

    I've had issues in this area recently, and this is how I've solved similar
    problems, but someone else may point out a better or easier solution (or may
    even verify that you have located a bug that should be fixed).

    -Mike



    This archive was generated by hypermail 2.0.0 : Tue Oct 19 2004 - 13:21:22 EDT