NullPointerException when setting deletion rules

From: Peter (peatha..ahoo.de)
Date: Tue Nov 28 2006 - 17:48:01 EST

  • Next message: Michael Gentry: "Re: Re: Persistence and inheritance : a noob question"

    Hallo!

    I reduced my application code to the following:

    -------------------------------------------------
                ArrayList temporaryObjects = new ArrayList();
             DataContext context = DataContext.createDataContext();

             Room r = (Room) context.createAndRegisterNewObject(Room.class);

             r.setName("testRoom");
             temporaryObjects.add(r);

             TimeInterval ti =
    (TimeInterval)context.createAndRegisterNewObject(TimeInterval.class);
             temporaryObjects.add(ti);
             ti.setToOneTarget("room", r, false);

             context.deleteObjects(temporaryObjects);
             temporaryObjects.clear();

             context.commitChanges();
    -------------------------------------------------

    where I get a NPE at 'context.deleteObjects':

    -------------------------------------------------
    Exception in thread "main" java.lang.NullPointerException
             at
    org.objectstyle.cayenne.CayenneDataObject.removeToManyTarget(CayenneDataObject.java:281)
             at
    org.objectstyle.cayenne.access.DataContextDeleteAction.processDeleteRules(DataContextDeleteAction.java:239)
             at
    org.objectstyle.cayenne.access.DataContextDeleteAction.deleteNew(DataContextDeleteAction.java:149)
             at
    org.objectstyle.cayenne.access.DataContextDeleteAction.performDelete(DataContextDeleteAction.java:131)
             at
    org.objectstyle.cayenne.access.DataContext.deleteObject(DataContext.java:1043)
             at
    org.objectstyle.cayenne.access.DataContext.deleteObjects(DataContext.java:1027)
    -------------------------------------------------

    I don't get this if I do
    ti.setToOneTarget("room", r, -->true<--);

    But I need both: uni AND bidirectional relationships!
    Here the mapping:

    -------------------------------------------------
    <?xml version="1.0" encoding="utf-8"?>
    <data-map project-version="1.1">
            <property name="defaultPackage" value="caybug"/>
            <db-entity name="ROOM">
                    <db-attribute name="NAME" type="VARCHAR" length="24"/>
                    <db-attribute name="R_ID" type="INTEGER" isPrimaryKey="true"
    isMandatory="true"/>
            </db-entity>
            <db-entity name="TIME_INTERVAL">
                    <db-attribute name="ROOM_FK" type="INTEGER"/>
                    <db-attribute name="TI_ID" type="INTEGER" isPrimaryKey="true"
    isMandatory="true"/>
            </db-entity>
            <obj-entity name="Room" className="caybug.Room" dbEntityName="ROOM">
                    <obj-attribute name="name" type="java.lang.String"
    db-attribute-path="NAME"/>
            </obj-entity>
            <obj-entity name="TimeInterval" className="caybug.TimeInterval"
    dbEntityName="TIME_INTERVAL">
            </obj-entity>
            <db-relationship name="TIME_INTERVALS" source="ROOM"
    target="TIME_INTERVAL" toMany="true">
                    <db-attribute-pair source="R_ID" target="ROOM_FK"/>
            </db-relationship>
            <db-relationship name="ROOM" source="TIME_INTERVAL" target="ROOM"
    toMany="false">
                    <db-attribute-pair source="ROOM_FK" target="R_ID"/>
            </db-relationship>
            <obj-relationship name="timeIntervals" source="Room"
    target="TimeInterval" deleteRule="Nullify"
    db-relationship-path="TIME_INTERVALS"/>
            <obj-relationship name="room" source="TimeInterval" target="Room"
    deleteRule="Nullify" db-relationship-path="ROOM"/>
    </data-map>
    -------------------------------------------------

    What is wrong? I used the default generated Room and TimeInterval classes.

    Thank you, Peter.

            
                    
    ___________________________________________________________
    Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de



    This archive was generated by hypermail 2.0.0 : Tue Nov 28 2006 - 17:44:28 EST