• 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: Single-table Inheritance w/ one-to-many
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Single-table Inheritance w/ one-to-many


  • Subject: Re: Single-table Inheritance w/ one-to-many
  • From: Christian Brunschen <email@hidden>
  • Date: Sun, 25 Dec 2005 10:07:02 +0000


On 24 Dec 2005, at 23:29, Drew Thoeni wrote:

This question is similar to one I sent a while ago. However, I've changed the structure of my EOmodel and wanted to run this by the group.

I have an employee table. An employee can be a project owner, a consultant, or a client. Since an employee at one time or another could be (possibly) all three of these), I have attributes name isOwner, isConsultant, isClient. Since I want users to be able to add an employee one-time, the Employee class is not abstract. I have created sub-classes of Employee called, obviously, Owner, Consultant, and Client. The sub-classes use qualifiers like (isOwner = 1) to select the correct Employees for the sub-class. The Employee table has a qualifier of (employeeID > 0), which is always true and returns all rows.

The problem comes in when I am trying to allow a user to create (or edit, but we never get that far) a new record. If no employee has more than one sub-class, things are rosey. However, as soon as an employee has more than one flag checked (that two or more of these are true: isOwner, isConsultant, or isClient), WO believes the wrong Class is being returned an gives an error. This error is the result of a page where popup fields exist to select an owner, consultant, and client to assign to a project.

java.lang.IllegalArgumentException: While trying to set the field "consultant" on an object of type ProjectDetailPage we expected a Consultant but received a Client with a value of...

Now, I'm sure I'm wrong here, but it seems that the NSArray I have built for owners, consultants, and clients are all separate objects. And just because we have the same employee appearing in two of these NSArrays (say Joe is listed both in owner and consultant), WO should not go wacky and it should just display Joe in the owner popup and the consultant popup.

What am I missing?


An object in Java (and indeed most languages) can be of exactly one class. It can never be of more, or less, than one class; it can't usually even change its class during its lifetime.

Basically, you can't use subclassing and entity inheritance to model what you are trying to do. 

You simply need one single Employee class, with the attributes to specify what sort of employee it is - isConsultant, isClient. I'd actually not have an 'isOwner' attributes, but instead have a relationship from the Employee to the project(s) that thsi employee owns. If the  employee owns at least one project, then they are per definition a project owner.

But just to reiterate: You cannot have an entity whose instances can be of less or more then one class, or whose instances can 'change their class' - because those are not supported states and actions in Java, or in WebObjects.

Regards (and Merry Christmas),

Best wishes (and Happy Holidays!)

Drew

// Christian Brunschen

 _______________________________________________
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

  • Follow-Ups:
    • Re: Single-table Inheritance w/ one-to-many
      • From: Arturo PĂ©rez <email@hidden>
References: 
 >Single-table Inheritance w/ one-to-many (From: Drew Thoeni <email@hidden>)

  • Prev by Date: Re: Dumb Question: Automatically running wotaskd and javamonitor?
  • Next by Date: NeXT Pictures from WWDC
  • Previous by thread: Single-table Inheritance w/ one-to-many
  • Next by thread: Re: Single-table Inheritance w/ one-to-many
  • Index(es):
    • Date
    • Thread