• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Vertical inheritance with a non-abstract superclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Vertical inheritance with a non-abstract superclass


  • Subject: Re: Vertical inheritance with a non-abstract superclass
  • From: David Elliott <email@hidden>
  • Date: Sat, 8 Mar 2008 14:03:45 -0500

Hi Nathan,

Your problem is that your superclass is non-abstract. If you really do want instances of your superclass then you MUST write a qualifier to distinguish records in your base table that need to instantiate an object of your base class vs. records that have data in some other table that will need to be instantiated as one of your subclasses.

Generally what I recommend is to make your superclass abstract. Then add another subclass with another table. That table needs to contain no columns except for the PK column(s).

So instead of having this:
MyEntity
MySpecialEntity  : MyEntity
MyOtherSpecialEntity  : MyEntity

you have this:
MyEntity - abstract
MyNonSpecialEntity : MyEntity
MySpecialEntity  : MyEntity
MyOtherSpecialEntity  : MyEntity

You see, what happens in EOF is that when you fetch records of the base class EOF also fetches all subclass records usually by selecting everything in all of the tables one after the other. So in your original code it does something like this:

select * from my_entity;
select * from my_special_entity inner join my_entity using (my_entity_id);
select * from my_other_special_entity inner join my_entity using (my_entity_id);


That doesn't work because MyEntity is not abstract and thus my_entity contains a record not only for the objects that are instances of MyEntity but also all of its subclasses. So after creating instances of MyEntity for all the records in my_entity that should have been for subclasses EOF fetches the subclass records and now you have an inconsistency because most of those records fetched from my_entity should have been instances of a subclass.

Once you change MyEntity to be abstract and add the new subclass there is no longer any need to select * from my_entity and EOF will do this instead:

select * from my_non_special_entity inner join my_entity using (my_entity_id);
select * from my_special_entity inner join my_entity using (my_entity_id);
select * from my_other_special_entity inner join my_entity using (my_entity_id);


This is more likely to be what you want. Note that my_non_special_entity will only contain the PK column(s) and serves only to let EOF identify which records belong to which class. Since MyEntity is abstract, no records in my_entity can ever instantiate a MyEntity.

-Dave

On Mar 8, 2008, at 8:50 AM, Nathan Gabrish wrote:

I am attempting to create a subclass by inheriting from a non- abstract superclass using the vertical inheritance method. I have followed the steps outlined in Apples documentation for EOModeler but I am still getting consistency checks when I save.

The consistency check that is returned when I attempt to save is as follows:
"Entity Superclass (parent entity of Subclass) needs a restricting qualifier in order to filter out rows in table SUPER that are only holding data for Subclass instances"


The documentation is a little unclear (to me at least) as to whether or not I really do need a restricting qualifier when using vertical inheritance but I have tried adding it anyway. I have tried adding the qualifier both to the superclass and subclass but I still get the consistency check in each case. The only way I have found to get around the consistency check is to mark the superclass as abstract, however I need to be able to instantiate objects of the superclass in this case so that is not going to work for me.

Is it possible that the consistency check is just a bug in this case because EOModeler does not recognize which tye of inheritance mapping I am using?

I am currently using version 5.1 of Webobjects.
_______________________________________________
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
References: 
 >Vertical inheritance with a non-abstract superclass (From: "Nathan Gabrish" <email@hidden>)

  • Prev by Date: EOGenerator failed with code #133.
  • Next by Date: Re: dyld 2 questions
  • Previous by thread: Vertical inheritance with a non-abstract superclass
  • Next by thread: Re: Vertical inheritance with a non-abstract superclass
  • Index(es):
    • Date
    • Thread