Re: ToOneRelationship and saveChange method
Re: ToOneRelationship and saveChange method
- Subject: Re: ToOneRelationship and saveChange method
- From: Kieran Kelleher <email@hidden>
- Date: Tue, 20 Sep 2011 04:46:07 -0400
You don't say how many contacts you are adding to the campaign <<-->> contacts relationship, but based on the description of you problem I am assuming it is huge, way beyond 10,000, maybe beyond 100,000 or 1,000,000.
In any case, it seems like you are hitting the EOF huge to-many relationship (EOF comparing the previous huge NSArray of to-many items to the new huge changed to-many item NSArray) problem…. and yes, this kills performance. For simple to-many A<-->> B solving it is a little easier. For many-to-many, it is solved in a similar way.
So you have something like the following, where xxcampaigncontact is the assumed name of the "join" entity:
campaign <-->> xxcampaigncontact <<--> contact
You need to change your EOModel as follows by deleting both the "contacts" item and the grayed out 'xxcampaigncontact' items in the relationship section of the 'campaign' entity. Thus you are removing the offending huge to-many between campaign and xxcampaigncontact.
campaign <-- xxcampaigncontact <<--> contact
Then you will need to write business logic methods in your campaign.java class to fetch contacts and do other contact manipulation using "reverse relationship" (contact to campaigns) manipulation logic.
For example, you may want to add a contactsQualifier() method to campaign that will look like this:
protected EOQualifier _contactsQualifier;
public EOQualifier contactsQualifier() {
if (_contactsQualifier == null) {
_contactsQualifier = Contact.CAMPAIGNS_KEY.containsObject(this);
}
return _contactsQualifier;
}
And then to fetch a campaign's contacts, use a fetch spec having the qualifier above.
To add contacts to a campaign's contacts, you convenience method in your campaign.java to add the campaign to a contact's campaigns relationship instead.
contact.addToCampaignsRelationship( campaign );
In the case of a regular huge to-many relationship, a convenience class like ERXUnmodeledToManyRelationship can be used. Referring to this may help you get your head around your current problem.
HTH, Kieran
On Sep 20, 2011, at 2:56 AM, Jérémy DE ROYER [INGENCYS] wrote:
> Hi All,
>
> I have an editing context question.
>
> I've got 2 tables : contact and compaign
>
> I want to add contacts to a compaign so I've created a many to many relationship between the table contact and the table compaign. That work fine.
>
> Problem is that when I add (lots of) contacts to a compaign because webobjects, when updating database with saveChanges(), update all contacts in database (even if fields of contacts haven't been changed).
>
> For table with 5 rows, I takes 20 secondes for 1000 added contacts, that's ok.
>
> But for table with more than 50 rows, I takes more than 2 minutes.
>
> What's the best solution to avoid that wast of time (that make problem when submitting form that takes to many time... for nothing)
>
> I though about :
> - creating "linking" table with no data row to avoid long save, but I have to change all my model...
> - remove contact from updatedObjects set, but that's dirty because willUpdate methods won't be called
>
> Any idea to avoir SQL update on objects that didn't changes except to Many Relationship ?
>
> Jérémy _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden