The problem appeared when we decided to use addObjectToBothSidesOfRelationship whenever we set an eo relationship.
Here is my code :
public WOComponent book() {
// create the campaign object
MediaBookingCampaign campaign = (MediaBookingCampaign) EOUtilities.createAndInsertInstance(childEC, "MediaBookingCampaign");
campaign.setAccountRelationship(media.account()); // this does an addObjectToBothSidesOfRelationship which works
campaign.setCost(new Double(totalCost));
campaign.setName(campaignName);
campaign.setMediaRelationship(media); // this does an addObjectToBothSidesOfRelationship which works
// create the mediaBookings objects
processBooking(campaign, null, null);
// save the syncBookings
childEC.saveChanges();
session().defaultEditingContext().saveChanges();
return pageWithName("com.easyshadow.webui.booking.MediaBookingsComponent");
}
/**
* create all the necessary mediaBookings objects for the MediaBookingCampaign
*/
private void processBooking(MediaBookingCampaign mediaBookingCampaign) {
Playlist playlist;
MediaBooking mediaBooking;
for (int i = 0; i < selectedPlaylists.count(); i++) {
playlist = (Playlist) selectedPlaylists.objectAtIndex(i);
// if there is some playtimes, create the mediaBookings
if (!playtimes.equals("0")) {
mediaBooking = (MediaBooking) EOUtilities.createAndInsertInstance(childEC, "MediaBooking");
mediaBooking.setMediaRelationship(media);
mediaBooking.setMediaBookingCampaignRelationship(mediaBookingCampaign);
mediaBooking.setPlaylistRelationship(playlist);
mediaBooking.setBookingDate(new Long(new GregorianCalendar(TimeZone.getTimeZone("GMT")).getTimeInMillis()));
}
}
}
Before saving the default editing context (in book() ), I checked that in it :
- all inserted objects (both the MediaBooking and the MediaBookingCampaign are here) are in the default editing context
- all changed objects (both the MediaBooking and the MediaBookingCampaign are here) are in the default editing context
But I end up with a :
java.lang.IllegalStateException: Cannot obtain globalId for an object which is registered in an other than the databaseContext's active editingContext
in com.webobjects.eoaccess.EODatabaseContext._globalIDForObject
It seems I have a MediaBooking in the childEc !
Where does that one come from ???
Thanks to anyone who could help !
Fabrice
__ Jerry W. Walker,