Tutorial DeletePage added by Andrus AdamchikThis section explains how to model relationship delete rules and how to delete individual objects as well as sets of objects. Also demonstrated the use of Cayenne class to run a query. Setting Up Delete RulesBefore we discuss the API for object deletion, lets go back to CayenneModeler and set up some delete rules. Doing this is optional but will simplify correct handling of the objects related to deleted objects. In the Modeler go to "Artist" ObjEntity, "Relationships" tab and select "Cascade" for the "paintings" relationship delete rule: Unable to render embedded object: File (modeler-deleterule.png) not found. Repeat this step for other relationships:
Now save the mapping, and refresh the project in Eclispe. Deleting ObjectsWhile deleting objects is possible via SQL, qualifying a delete on one or more IDs, a more common way in Cayenne (or ORM in general) is to get a hold of the object first, and then delete it via the context. Let's use utility class Cayenne to find an artist: _expression_ qualifier = ExpressionFactory.matchExp(Artist.NAME_PROPERTY, "Pablo Picasso"); SelectQuery select = new SelectQuery(Artist.class, qualifier); Artist picasso = (Artist) Cayenne.objectForQuery(context, select);
Change Notification Preferences
View Online
|
Add Comment
|
- [CONF] Apache Cayenne Documentation > Tutorial Delete confluence
