You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Andrus Adamchik <an...@objectstyle.org> on 2006/12/01 12:53:31 UTC

Re: NullPointerException when setting deletion rules

Hmm... I'd say Cayenne should be smarter about this case. Could you  
please open a bug report?


In the meantime you may have to manually break relationship cycles  
before deleting objects. E.g.:

ti.setToOneTarget("room", null, false);

Andrus


On Nov 29, 2006, at 1:48 AM, Peter wrote:
> 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.processDeleteRu 
> les(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.


Re: NullPointerException when setting deletion rules

Posted by Peter Karich <pe...@yahoo.de>.
Hallo again!

Now the 'real' applications works, too!
A second possible solution (only for the case of my app) is to delete 
the timeintervals before the rooms!



Thank you, Peter.



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

Re: NullPointerException when setting deletion rules

Posted by Peter Karich <pe...@yahoo.de>.
Hallo!

Thank you Andrus, I will try it out. In my prepared example this fix helps!

> In the meantime you may have to manually break relationship cycles 
> before deleting objects. E.g.:
> ti.setToOneTarget("room", null, false);
Puuh, I have a lot of TimeIntervals in my real app :-)

 > Hmm... I'd say Cayenne should be smarter about this case.
 > Could you please open a bug report?
I have never done before so take a look, please.

Peter.

PS: Michael Gentry, thank you for the link!! 
(http://www.stepwise.com/Articles/2005/DBChanges/index.html)

		
___________________________________________________________ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de