> 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@hidden>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(EORelati
> onship.java:1134)
>>> at
>>>
>
com.webobjects.eoaccess.EORelationship._foreignKeyForSourceRow(EORelationship
> .java:1148)
>>> at
>>>
>
com.webobjects.eoaccess.EODatabaseContext._objectFaultWithSnapshotRelationshi
> pEditingContext(EODatabaseContext.java:2346)
>>> at
>>>
>
com.webobjects.eoaccess.EODatabaseContext._fireDeferredFaultWithSourceObject(
> EODatabaseContext.java:2401)
>>> at
>>>
>
com.webobjects.eoaccess.EOAccessDeferredFaultHandler.createFaultForDeferredFa
> ult(EOAccessDeferredFaultHandler.java:49)
>>> at
>>>
>
com.webobjects.eocontrol.EOCustomObject.willReadRelationship(EOCustomObject.j
> ava:1279)
>>> at
>>>
>
er.extensions.eof.ERXGenericRecord.willReadRelationship(ERXGenericRecord.java
> :358)
>>> at
>>>
>
com.webobjects.eocontrol._EOMutableKnownKeyDictionary$Initializer$_LazyGeneri
> cRecordBinding.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.j
> ava:2813)
>>> at er.extensions.eof.ERXEC.objectWillChange(ERXEC.java:769)
>>> at
>>>
>
com.webobjects.eocontrol.EOObserverCenter.notifyObserversObjectWillChange(EOO
> bserverCenter.java:399)
>>> at
>>>
com.webobjects.eocontrol.EOCustomObject.willChange(EOCustomObject.java:333)
>>> at
>>>
>
com.webobjects.eocontrol._EOMutableKnownKeyDictionary$Initializer$_GenericRec
> ordBinding.setValueInObject(_EOMutableKnownKeyDictionary.java:579)
>>> at
>>>
>
com.webobjects.eocontrol.EOCustomObject.takeStoredValueForKey(EOCustomObject.
> java:1663)
>>> at
>>>
>
er.extensions.eof.ERXGenericRecord.takeStoredValueForKey(ERXGenericRecord.jav
> a: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(NSK
> eyValueCoding.java:643)
>>> at
>>>
>
com.webobjects.foundation.NSKeyValueCoding$_MethodBinding.setValueInObject(NS
> KeyValueCoding.java:1150)
>>> at
>>>
>
com.webobjects.eocontrol.EOCustomObject.takeValueForKey(EOCustomObject.java:1
> 529)
>>> at
>>>
>
er.extensions.eof.ERXGenericRecord.takeValueForKey(ERXGenericRecord.java:1282
> )
>>> at
>>>
>
com.webobjects.foundation.NSKeyValueCoding$Utility.takeValueForKey(NSKeyValue
> Coding.java:469)
>>> at
>>>
>
com.webobjects.foundation.NSValidation$DefaultImplementation.validateTakeValu
> eForKeyPath(NSValidation.java:679)
>>> at
>>>
>
com.webobjects.eocontrol.EOCustomObject.validateTakeValueForKeyPath(EOCustomO
> bject.java:1335)
>>> at
>>>
>
com.webobjects.foundation.NSValidation$Utility.validateTakeValueForKeyPath(NS
> Validation.java:502)
>>> at
>>>
>
com.webobjects.foundation.NSValidation$DefaultImplementation.validateTakeValu
> eForKeyPath(NSValidation.java:687)
>>> at
>>>
>
com.webobjects.eocontrol.EOCustomObject.validateTakeValueForKeyPath(EOCustomO
> bject.java:1335)
>>> at
>>>
>
com.webobjects.foundation.NSValidation$Utility.validateTakeValueForKeyPath(NS