Here's the problem (from the docs).
file://localhost/C|/Apple/Documentation/Developer/EnterpriseObjects/Guide/EOsII3.html
There are workarounds... My favorite is to model the relationship as a
to-many with to-one'ish accessors on Class1... Here's an example from
the docs of this approach:
public void setTalentPhoto(TalentPhoto talentPhoto){
willChange();
_talentPhotoArray.removeAllObjects();
if (talentPhoto != null)
_talentPhotoArray.addObject(talentPhoto);
}
public TalentPhoto talentPhoto(){
willRead();
if (_talentPhotoArray.count() > 0)
return _talentPhotoArray.objectAtIndex(0);
return null;
}
d
----
Java Limitation With Ambiguous To-One Relationships
In both Java and Objective-C you can have to-many relationships to
instances of both leaf and non-leaf subclasses in your class hierarchy.
For example, the SoftballTeam entity can have a to-many relationship to
Person or just the Employee entity (as in a company only team).
Similarly, you can have to-one relationships to instances of leaf
subclasses. For example, the PurchaseOrder entity can have a to-one
relationship to the Customer entity.
However, in Java you can not have a to-one relationship to a non-leaf
entity, an ambiguous to-one relationship, unless you implement a
workaround. Ambiguous to-one relationships are not possible in Java
because of strong typing in the language. In Objective-C, the class of
an instance can be changed after it is instantiated (i.e., from the
parent class to the leaf class).
There are two workarounds for Java programmers. You can encode class
information in your primary and foreign keys, and implement
EOModelGroup's delegate methods as described in "Delegation Hooks for
Optimizing Inheritance". If you choose this option, then consider using
single table mapping since the table would already contain class
information.
The second workaround is to implement the ambiguous to-one relationship
as a to-many, similar to dealing with an optional to-one relationship
above. "Use a To-Many Relationship"
"Ladia, Darius D" wrote:
>
> Hi -
>
> I'm using WO 4.0 on Windows NT 4.0 (using Java).
>
> I have a simple EOModel:
>
> Class 1: No parent, To-one relation to Class2, One String attribute
> Class 2: No parent, ABSTRACT, One String attribute
> Class 2A: Parent is Class2, One String attribute
> Class 2B: Parent is Class2, One String attribute
>
> If I try displaying all of the Class1 instances in a repetition, I get:
>
> NSInternalInconsistencyException: Exception occured while evaluating
> 'class1list', on target:<Main 0xa95970>:
> A fault was fired while another fetch was in progress and no other channels
> were available to process the fault. Either make sure not to touch faults
> while fetching, or register more channels with the EODatabaseContext
> (perhaps in response to the EODatabaseChannelNeededNotification). Original
> Exception: _obtainOpenChannel -- EODatabaseContext 0xa83ed0: no database
> channel is available
>
> So, I register new Database channels in response to the
> EODatabaseChannelNeededNotification with:
>
> public void databaseChannelNeededNotification(NSNotification
> notification) {
> EODatabaseContext dbcontext = (EODatabaseContext)
> notification.object();
> EODatabaseChannel channel = new EODatabaseChannel(dbcontext);
> if (channel != null) {
> dbcontext.registerChannel(channel);
> }
>
> Now the application crashes (Windows exception), with this:
>
> NSInternalInconsistencyException: Exception occured while evaluating
> 'class1list', on target:<Main 0xa93fb0>:
> Init return a different object <Class2B: 0xaba360>
>
> When Zombies are enabled, it turns out the crash is caused by:
> *** *** Selector 'release' sent to dealloced instance 0xad2350 of class
> Class2B.
>
> Any ideas what the next step would be?
>
> Darius Ladia
> Electronic Data Systems
> [EMAIL PROTECTED]