You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Brian Nelson <br...@yahoo.com> on 2008/04/30 07:04:16 UTC

Error when adding and then removing object from relationship before committing

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







Re: Error when adding and then removing object from relationship before committing

Posted by Brian Nelson <br...@yahoo.com>.
Kevin,

Thanks for the encouragement to ask questions. The Cayenne communities openness to answering
questions was the main reason I switched to Cayenne from Hibernate(the other being your an Apache
project). I was really struggling with aspects of Hibernate and it seemed like anyone who asked
questions got abused and treated as though they were stupid. It's nice to not have to deal with
those types of antics.

Brian


--- Kevin Menard <km...@servprise.com> wrote:

> Hi Brian,
> 
> On Apr 30, 2008, at 1:04 AM, Brian Nelson wrote:
> 
> > 2. Is this a known issue with a workaround. Yes I've searched, and  
> > searched, and searched both the
> > mailing list and JIRA.
> 
> 
> This is nice to see, but you don't need to kill yourself searching.   
> We're not the kind of community to flame people for not being able to  
> find a post from two years back.  Obviously we'd like to see you put a  
> little time into it so you're not asking something that should be  
> readily apparent.  But, please feel free to ask your questions here.   
> A culture of flaming & fear really doesn't benefit anyone.
> 
> -- 
> Kevin
> 



Re: Error when adding and then removing object from relationship before committing

Posted by Kevin Menard <km...@servprise.com>.
Hi Brian,

On Apr 30, 2008, at 1:04 AM, Brian Nelson wrote:

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


This is nice to see, but you don't need to kill yourself searching.   
We're not the kind of community to flame people for not being able to  
find a post from two years back.  Obviously we'd like to see you put a  
little time into it so you're not asking something that should be  
readily apparent.  But, please feel free to ask your questions here.   
A culture of flaming & fear really doesn't benefit anyone.

-- 
Kevin

Re: Error when adding and then removing object from relationship before committing

Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 01/05/2008, at 3:07 PM, Brian Nelson wrote:

> Thanks so much for the fast response. Now what is the best way for  
> me to get the latest cayenne so
> I can test this in my application?

Go to the Cayenne web site and click "download" in the left menu.  
You'll find milestones, stable releases and nightly builds.

Ari



-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A



Re: Error when adding and then removing object from relationship before committing

Posted by Brian Nelson <br...@yahoo.com>.
Thanks so much for the fast response. Now what is the best way for me to get the latest cayenne so
I can test this in my application?

Brian


--- Andrus Adamchik <an...@objectstyle.org> wrote:

> Hi Brian,
> 
> On Apr 30, 2008, at 8:04 AM, Brian Nelson wrote:
> 
> > 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.
> 
> Cool. Would be nice to hear the details ;-)
> 
> 
> > 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.
> 
> This turned out to be a bug. I already committed the fix. It will be a  
> part of M4:
> 
> https://issues.apache.org/cayenne/browse/CAY-1044
> 
> Andrus
> 


Re: Error when adding and then removing object from relationship before committing

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Brian,

On Apr 30, 2008, at 8:04 AM, Brian Nelson wrote:

> 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.

Cool. Would be nice to hear the details ;-)


> 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.

This turned out to be a bug. I already committed the fix. It will be a  
part of M4:

https://issues.apache.org/cayenne/browse/CAY-1044

Andrus