Error when adding and then removing object from relationship before committing

From: Brian Nelson (briannelson2..ahoo.com)
Date: Wed Apr 30 2008 - 01:04:16 EDT

  • Next message: Alexis: "Re: Does DataContext.rollbackChanges() in 1.1.4 leave transient objects in toManyList relationships?"

    Let me start this post by thanking the Cayenne dev team for their great work. The project I'm
    working on switched from Hibernate to Cayenne several months ago. I can honestly say the decision
    to switch is one of the best things that ever happened to my project.

    Now on to my problem...

    I have a situation where I

    1. Add a newly created object to a relationship.

            EstimateRoom room = context.newObject(EstimateRoom.class);

            // Several lines configuring variables in room
            
            floorModel.getEstimate().addToRooms(room);

    2. Remove the object from the relationship

            estimate.removeFromRooms(obj);
                context.deleteObject(obj);

    3. Attempt to commit to the parent DataContext

    This works as long as the object is the last element contained in the List maintaining the
    relationship. If it is in the middle of the List(I sort the list after the room is inserted) then
    I receive the following exception.

    [v.3.0M3 Jan 27 2008 20:12:33] Commit Exception
    org.apache.cayenne.CayenneRuntimeException: [v.3.0M3 Jan 27 2008 20:12:33] Commit Exception
            at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1207)
            at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1088)
            at com.logicalsolutions.estimator.estimate.EstimatePanel.onApply(EstimatePanel.java:1522)
            at com.logicalsolutions.estimator.estimate.EstimatePanel.vaidateAndSave(EstimatePanel.java:1386)
            at
    com.logicalsolutions.estimator.estimate.EstimatePanel$20.actionPerformed(EstimatePanel.java:1323)
            at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
            at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
            at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
            at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
            at java.awt.Component.processMouseEvent(Unknown Source)
            at javax.swing.JComponent.processMouseEvent(Unknown Source)
            at java.awt.Component.processEvent(Unknown Source)
            at java.awt.Container.processEvent(Unknown Source)
            at java.awt.Component.dispatchEventImpl(Unknown Source)
            at java.awt.Container.dispatchEventImpl(Unknown Source)
            at java.awt.Component.dispatchEvent(Unknown Source)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
            at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
            at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
            at java.awt.Container.dispatchEventImpl(Unknown Source)
            at java.awt.Window.dispatchEventImpl(Unknown Source)
            at java.awt.Component.dispatchEvent(Unknown Source)
            at java.awt.EventQueue.dispatchEvent(Unknown Source)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
            at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
            at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
            at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
            at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.NullPointerException: Attempt to add null target DataObject.
            at org.apache.cayenne.CayenneDataObject.addToManyTarget(CayenneDataObject.java:262)
            at
    org.apache.cayenne.reflect.generic.DataObjectToManyProperty.addTarget(DataObjectToManyProperty.java:72)
            at org.apache.cayenne.access.ChildDiffLoader$1.visitToMany(ChildDiffLoader.java:131)
            at
    org.apache.cayenne.reflect.generic.DataObjectToManyProperty.visit(DataObjectToManyProperty.java:112)
            at org.apache.cayenne.access.ChildDiffLoader.arcCreated(ChildDiffLoader.java:119)
            at org.apache.cayenne.access.ObjectDiff$ArcOperation.apply(ObjectDiff.java:445)
            at org.apache.cayenne.graph.CompoundDiff.apply(CompoundDiff.java:92)
            at org.apache.cayenne.access.ObjectStoreGraphDiff.apply(ObjectStoreGraphDiff.java:135)
            at org.apache.cayenne.access.DataContext.onContextFlush(DataContext.java:1135)
            at org.apache.cayenne.access.DataContext.onSync(DataContext.java:1117)
            at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1175)
            ... 29 more

    So a few questions...
    1. Is it OK to sort the Lists that represent the relationships.

    2. Is this a known issue with a workaround. Yes I've searched, and searched, and searched both the
    mailing list and JIRA.

    3. How do I get more information about what's really going on in Cayenne. Is there a way to see
    more than what is included in the Exception stack trace.

    Any help is very much appreciated!

    Brian



    This archive was generated by hypermail 2.0.0 : Wed Apr 30 2008 - 01:04:51 EDT