Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Won't Fix
    • Affects Version/s: 1.1 [LEGACY]
    • Fix Version/s: None
    • Component/s: Core Library
    • Labels:
      None
    • Environment:
      mySQL 4.0.12
      Cayenne Modeler 1.1RC1 (October 3 2004)
      Java 1.4.2

      Description

      Objects are connected with relations per ID, deletion should be per cascade.

      Object1 has more than one involved related Objects2-9
      over more than one step to bottom
      which should all be deleted
      only by DataContext.deleteObject(Object1) per cascade.

      If a Object5, stands 2 steps under Object1 has a invalid ID, so will an Exception be thrown from CayenneDataObject.resolveFault().

      The result is, that the upper Object1 is deleted, but after Exception the rest of related Objects, don't be deleted per cascade, they are garbage in the database.

      Kind regards
      Katrin

        Activity

        Hide
        Andrus Adamchik added a comment -

        Katrin,

        Hmm ... looks like you are hitting the problem with lack of transactional behavior in MySQL (if commit can't finish a "normal" db would rollback any half-way made changes, while MySQL will keep the DB in the inconsistent state). I think MySQL 4.0 supports transactions, but this requires tables to be created in a special way. Take a look at MySQL docs for details.

        Still I am not closing this report yet, as I don't fully understand the scenario you describe. So here is some questions that will hopefully help me to confirm whether this is a Cayenne or MySQL problem:

        1. Do you have "CASCADE" delete rule set up in CayenneModeler, so that deleting a "root" of the object hierarchy automatically cascads deletion of "children"?

        2. Can you attach a full exception stack trace?

        3. Whay is there an "invalid ID"?

        Please post the answers as "Comments" on this issue.

        Thanks
        Andrus

        Show
        Andrus Adamchik added a comment - Katrin, Hmm ... looks like you are hitting the problem with lack of transactional behavior in MySQL (if commit can't finish a "normal" db would rollback any half-way made changes, while MySQL will keep the DB in the inconsistent state). I think MySQL 4.0 supports transactions, but this requires tables to be created in a special way. Take a look at MySQL docs for details. Still I am not closing this report yet, as I don't fully understand the scenario you describe. So here is some questions that will hopefully help me to confirm whether this is a Cayenne or MySQL problem: 1. Do you have "CASCADE" delete rule set up in CayenneModeler, so that deleting a "root" of the object hierarchy automatically cascads deletion of "children"? 2. Can you attach a full exception stack trace? 3. Whay is there an "invalid ID"? Please post the answers as "Comments" on this issue. Thanks Andrus
        Hide
        Katrin Dorendorf added a comment -

        Hallo Andrus,

        thank you for your answer, I'll describe details, perhaps this will
        explain something or not ..?
        Ok, something I hadn't correct describbed.

        1) I know invalide ID's should not happen and I think that they are not
        come from Cayenne (they are older, probably per direct intervention by
        hand in DB)
        Perhaps thats why my question wasn't wise.

        But I'll continue to explain the scenario
        2) There are objects connected, most of them have cascade deleting rule
        and a few not.
        obj1 <> obj2 <> obj3 (1<>2 one2many | 2<>3 many2one
        obj1 <-> obj2 with cascade del. rule
        obj2 <-> obj3 without.
        obj3 don't exist, but the ID is in obj2 (ID=Integer(0), but 0 could be
        also another Integer)

        I have to say, that I have done some intervention with Cayenne sources
        for case 2 in order to delete also the last obj2<->obj3 connection
        automatically:

        class Events (= obj2) ...
        public void setPersistenceState (int persistenceState) {
        if (persistenceState == PersistenceState.DELETED) {
        try {
        Docobj doc = this.getDocobj ();
        if( doc != null )
        {
        doc.removeFromEventsArray (this);
        List list = doc.getEventsArray ();
        if( list == null || list.size () < 1 )

        { doc.setPersistenceState (PersistenceState.DELETED); }

        }
        }
        catch( Exception ex) {}
        }
        super.setPersistenceState (persistenceState);
        }

        The Docobj (= obj3) had the invalid ID.
        But the error wasn't here, the error was later only by

        DataContext.deleteObject(obj1) by obj..resolveFault();

        Ok, the exception is in a try/catch catched.
        But if the window is further open and the DataContext will later once
        more committed it will happen.

        The result: obj1 -> is deleted. but some ob2 relations are further in DB
        (This happens only by this invalide ID, otherwise all Ok).

        3) exception stack trace
        04.11.2004;19:15:38;122;GOA;...;313;Orgtre.delObjectStructure: Fehler
        beim Löschen der Object structure [abc]
        EXCEPION: org.objectstyle.cayenne.CayenneRuntimeException: [v.1.1B2 July
        25 2004] Error resolving fault, no matching row exists in the database
        for ObjectId: ...models.Docobj: <dok_id: 0>
        StackTrace:
        org.objectstyle.cayenne.CayenneRuntimeException: [v.1.1B2 July 25 2004]
        Error resolving fault, no matching row exists in the database for
        ObjectId: ...models.Docobj: <dok_id: 0>
        at
        org.objectstyle.cayenne.CayenneDataObject.resolveFault(CayenneDataObject.java:217)
        at
        org.objectstyle.cayenne.access.DataContext.deleteObject(DataContext.java:1010)
        at
        org.objectstyle.cayenne.access.DataContext.deleteObject(DataContext.java:1092)
        at
        org.objectstyle.cayenne.access.DataContext.deleteObject(DataContext.java:1092)
        at
        org.objectstyle.cayenne.access.DataContext.deleteObject(DataContext.java:1092)
        at
        ...models.Orgtre.delObjectStructure(Orgtre.java:565)

        How I said Integer(0) could be also another Integer but the
        correspondent Docobj wasn't existend, invalide ID probable inserted by
        hand at the beginning stage, but nevertheless, should man count on it?

        Katrin

        Show
        Katrin Dorendorf added a comment - Hallo Andrus, thank you for your answer, I'll describe details, perhaps this will explain something or not ..? Ok, something I hadn't correct describbed. 1) I know invalide ID's should not happen and I think that they are not come from Cayenne (they are older, probably per direct intervention by hand in DB) Perhaps thats why my question wasn't wise. But I'll continue to explain the scenario 2) There are objects connected, most of them have cascade deleting rule and a few not. obj1 < > obj2 < > obj3 (1< >2 one2many | 2< >3 many2one obj1 <-> obj2 with cascade del. rule obj2 <-> obj3 without. obj3 don't exist, but the ID is in obj2 (ID=Integer(0), but 0 could be also another Integer) I have to say, that I have done some intervention with Cayenne sources for case 2 in order to delete also the last obj2<->obj3 connection automatically: class Events (= obj2) ... public void setPersistenceState (int persistenceState) { if (persistenceState == PersistenceState.DELETED) { try { Docobj doc = this.getDocobj (); if( doc != null ) { doc.removeFromEventsArray (this); List list = doc.getEventsArray (); if( list == null || list.size () < 1 ) { doc.setPersistenceState (PersistenceState.DELETED); } } } catch( Exception ex) {} } super.setPersistenceState (persistenceState); } The Docobj (= obj3) had the invalid ID. But the error wasn't here, the error was later only by DataContext.deleteObject(obj1) by obj..resolveFault(); Ok, the exception is in a try/catch catched. But if the window is further open and the DataContext will later once more committed it will happen. The result: obj1 -> is deleted. but some ob2 relations are further in DB (This happens only by this invalide ID, otherwise all Ok). 3) exception stack trace 04.11.2004;19:15:38;122;GOA;...;313;Orgtre.delObjectStructure: Fehler beim Löschen der Object structure [abc] EXCEPION: org.objectstyle.cayenne.CayenneRuntimeException: [v.1.1B2 July 25 2004] Error resolving fault, no matching row exists in the database for ObjectId: ...models.Docobj: <dok_id: 0> StackTrace: org.objectstyle.cayenne.CayenneRuntimeException: [v.1.1B2 July 25 2004] Error resolving fault, no matching row exists in the database for ObjectId: ...models.Docobj: <dok_id: 0> at org.objectstyle.cayenne.CayenneDataObject.resolveFault(CayenneDataObject.java:217) at org.objectstyle.cayenne.access.DataContext.deleteObject(DataContext.java:1010) at org.objectstyle.cayenne.access.DataContext.deleteObject(DataContext.java:1092) at org.objectstyle.cayenne.access.DataContext.deleteObject(DataContext.java:1092) at org.objectstyle.cayenne.access.DataContext.deleteObject(DataContext.java:1092) at ...models.Orgtre.delObjectStructure(Orgtre.java:565) How I said Integer(0) could be also another Integer but the correspondent Docobj wasn't existend, invalide ID probable inserted by hand at the beginning stage, but nevertheless, should man count on it? Katrin
        Hide
        Andrus Adamchik added a comment -

        Katrin,

        I may need more time to look into that. One suggestion - could you upgrade to 1.1RC2 from 1.1B2 that you have now? Does anything change after the upgrade?

        Show
        Andrus Adamchik added a comment - Katrin, I may need more time to look into that. One suggestion - could you upgrade to 1.1RC2 from 1.1B2 that you have now? Does anything change after the upgrade?
        Hide
        Andrus Adamchik added a comment -

        Katrin, I was able to kind of reproduce the issue with this little attached test project. This is not a bug in Cayenne, rather your fault handler (Events.setPersistenceState..) is not doing the right thing. See E2.java in this example for a fault failure handler that seems to work. here is this code:

        public class E2 extends _E2 {

        public void setPersistenceState(int persistenceState) {
        if (persistenceState == PersistenceState.DELETED) {

        E3 e3 = this.getE3();

        // check for invalid target data
        try {
        if (e3 != null)

        { e3.resolveFault(); }

        }
        catch (CayenneRuntimeException ex)

        { ex.printStackTrace(); // invalid target, lets pretend that it does not exist... getDataContext().unregisterObjects(Collections.singleton(e3)); writePropertyDirectly(_E2.E3_PROPERTY, null); }

        }

        super.setPersistenceState(persistenceState);
        }
        }

        I hope this helps.

        Show
        Andrus Adamchik added a comment - Katrin, I was able to kind of reproduce the issue with this little attached test project. This is not a bug in Cayenne, rather your fault handler (Events.setPersistenceState..) is not doing the right thing. See E2.java in this example for a fault failure handler that seems to work. here is this code: public class E2 extends _E2 { public void setPersistenceState(int persistenceState) { if (persistenceState == PersistenceState.DELETED) { E3 e3 = this.getE3(); // check for invalid target data try { if (e3 != null) { e3.resolveFault(); } } catch (CayenneRuntimeException ex) { ex.printStackTrace(); // invalid target, lets pretend that it does not exist... getDataContext().unregisterObjects(Collections.singleton(e3)); writePropertyDirectly(_E2.E3_PROPERTY, null); } } super.setPersistenceState(persistenceState); } } I hope this helps.
        Hide
        Andrus Adamchik added a comment -

        Closing this issue... See my prevous comment and attched example.

        Andrus

        Show
        Andrus Adamchik added a comment - Closing this issue... See my prevous comment and attched example. Andrus

          People

          • Assignee:
            Andrus Adamchik
            Reporter:
            Katrin Dorendorf
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development