I would agree with you that this relationship is not guaranteed to be a
to-one relationship. However, I have coded my app in a way that I can
guarantee that it is a to-one relationship.

The only thing is I get that exception when I try to update state.seo
properties.

Then I tried to remove the class property of Seo.state(). The relationship
is still in tact but I can no longer access seo.state(). This seems to work,
but if there is a way that I can keep Seo.state() as a class property of Seo
and not get the exception on an update, that will really make my day.

Thanks Ken for the insight. Anyone else has some other idea?

Amiel

On Fri, Aug 28, 2009 at 12:01 PM, Ken Anderson <[email protected]>wrote:

> This relationship is not guaranteed to be to-one, since there could be many
> States that match the Seo's ID.
>
> The way I deal with this is to model it as a to-many relationship, and
> write methods in the EO that set/get, enforcing the to-one concept.
>
>
>
> On Aug 27, 2009, at 10:28 PM, Amiel Montecillo wrote:
>
>  Hello,
>>
>> I have a to-one relationship that is giving me problems when updating the
>> destination entity.
>>
>> class Seo
>> {
>>      id; <- PK
>>      title;
>>      description;
>>      state() <- reverse to-one relationship to State
>> }
>>
>> class State
>> {
>>       id; <- PK
>>       name;
>>       seoid; <- FK to Seo (id)
>>       seo(); <- optional to-one relationship to Seo
>> }
>>
>> When I first enter an Seo to a State, all seems fine, all properties of
>> Seo are saved and are related to the corresponding State. But then, when I
>> update it I get this exception.
>>
>>
>> Unable to map destination State for relationship state in entity Seo.  To
>> one relationships must be joined on the primary key of the destination.
>> java.lang.IllegalArgumentException: Unable to map destination State for
>> relationship state in entity Seo.  To one relationships must be joined on
>> the primary key of the destination.
>>    at
>> com.webobjects.eoaccess.EORelationship._sourceRowToForeignKeyMapping(EORelationship.java:1134)
>>    at
>> com.webobjects.eoaccess.EORelationship._foreignKeyForSourceRow(EORelationship.java:1148)
>>    at
>> com.webobjects.eoaccess.EODatabaseContext._objectFaultWithSnapshotRelationshipEditingContext(EODatabaseContext.java:2346)
>>    at
>> com.webobjects.eoaccess.EODatabaseContext._fireDeferredFaultWithSourceObject(EODatabaseContext.java:2401)
>>    at
>> com.webobjects.eoaccess.EOAccessDeferredFaultHandler.createFaultForDeferredFault(EOAccessDeferredFaultHandler.java:49)
>>    at
>> com.webobjects.eocontrol.EOCustomObject.willReadRelationship(EOCustomObject.java:1279)
>>    at
>> er.extensions.eof.ERXGenericRecord.willReadRelationship(ERXGenericRecord.java:358)
>>    at
>> com.webobjects.eocontrol._EOMutableKnownKeyDictionary$Initializer$_LazyGenericRecordBinding.valueInObject(_EOMutableKnownKeyDictionary.java:614)
>>    at
>> com.webobjects.eocontrol.EOCustomObject.storedValueForKey(EOCustomObject.java:1634)
>>    at
>> com.webobjects.eocontrol.EOCustomObject.snapshot(EOCustomObject.java:525)
>>    at
>> com.webobjects.eocontrol.EOEditingContext.objectWillChange(EOEditingContext.java:2813)
>>    at er.extensions.eof.ERXEC.objectWillChange(ERXEC.java:769)
>>    at
>> com.webobjects.eocontrol.EOObserverCenter.notifyObserversObjectWillChange(EOObserverCenter.java:399)
>>    at
>> com.webobjects.eocontrol.EOCustomObject.willChange(EOCustomObject.java:333)
>>    at
>> com.webobjects.eocontrol._EOMutableKnownKeyDictionary$Initializer$_GenericRecordBinding.setValueInObject(_EOMutableKnownKeyDictionary.java:579)
>>    at
>> com.webobjects.eocontrol.EOCustomObject.takeStoredValueForKey(EOCustomObject.java:1663)
>>    at
>> er.extensions.eof.ERXGenericRecord.takeStoredValueForKey(ERXGenericRecord.java:1290)
>>    at com.bossing.wo.bids.db._Seo.setDescription(_Seo.java:52)
>>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>    at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>    at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>    at java.lang.reflect.Method.invoke(Method.java:597)
>>    at
>> com.webobjects.foundation.NSKeyValueCoding$ValueAccessor$1.setMethodValue(NSKeyValueCoding.java:643)
>>    at
>> com.webobjects.foundation.NSKeyValueCoding$_MethodBinding.setValueInObject(NSKeyValueCoding.java:1150)
>>    at
>> com.webobjects.eocontrol.EOCustomObject.takeValueForKey(EOCustomObject.java:1529)
>>    at
>> er.extensions.eof.ERXGenericRecord.takeValueForKey(ERXGenericRecord.java:1282)
>>    at
>> com.webobjects.foundation.NSKeyValueCoding$Utility.takeValueForKey(NSKeyValueCoding.java:469)
>>    at
>> com.webobjects.foundation.NSValidation$DefaultImplementation.validateTakeValueForKeyPath(NSValidation.java:679)
>>    at
>> com.webobjects.eocontrol.EOCustomObject.validateTakeValueForKeyPath(EOCustomObject.java:1335)
>>    at
>> com.webobjects.foundation.NSValidation$Utility.validateTakeValueForKeyPath(NSValidation.java:502)
>>    at
>> com.webobjects.foundation.NSValidation$DefaultImplementation.validateTakeValueForKeyPath(NSValidation.java:687)
>>    at
>> com.webobjects.eocontrol.EOCustomObject.validateTakeValueForKeyPath(EOCustomObject.java:1335)
>>    at
>> com.webobjects.foundation.NSValidation$Utility.validateTakeValueForKeyPath(NSValidation.java:502)
>>
>> Is my entity modeling correct? Any ideas how I can resolve this?
>>
>> Thanks,
>> Amiel
>> --
>> socket error: unable to connect to 127.0.0.1
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list      ([email protected])
>> Help/Unsubscribe/Update your Subscription:
>>
>> http://lists.apple.com/mailman/options/webobjects-dev/kenlists%40anderhome.com
>>
>> This email sent to [email protected]
>>
>
>


-- 
socket error: unable to connect to 127.0.0.1
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to