Re: EOF inheritance
Re: EOF inheritance
- Subject: Re: EOF inheritance
- From: Lachlan Deck <email@hidden>
- Date: Wed, 9 Sep 2009 09:07:48 +1000
On 08/09/2009, at 5:11 PM, Timo Hoepfner wrote:
single table inheritance always worked fine for me. Random things to
watch out for:
- Be careful with NOT NULL constraints. Only make the columns in the
DB NOT NULL, when it must be NOT NULL in the *whole* inheritance
hierarchy (In Chuck and Sacha's most excellent book, there is a
section on that. Something like "the impossible constraint"). WOLips
takes care of that in most cases nowadays.
- Every non-abstract entity in the hierarchy needs a unique
restricting qualifier
- Don't forget to set the attribute that is used by the restricting
qualifier or switch on Wonder's auto-apply-restricting-qualifier
feature
- Don't try to change the type of an EO once it exists. It will
confuse EOF.
horizontal inheritance also works fine in most cases, but fails in
some situations. Random notes:
- Depending on the DB you use, you have to have tables for abstract
entities (e.g. in Frontbase you need a table for the root entity, as
PK generation relies on it)
That shouldn't be the case as that (== defining an external name for
the parent entity==) is vertical inheritance. And that sounds like the
bug which I addressed for 5.4 in ERXEntity#hasExternalName (the bug
being introduced in 5.4) because it was mucking up my vertical
inheritance stuff by creating auto_pk entries for the subclass instead
of the parent so that the pks were not unique across the VI tree.
(Abstract btw, for clarify, has nothing to do with whether or not the
entity maps to a table but whether or not it can be instantiated).
- Other than in single table inheritance, NOT NULL constraints are
not a problem, but you have to watch out for foreign key
constraints, when a relationship references an entity that has sub-
classes
- For some queries, the wrong SQL is generated, e.g. (still have the
repro code flying around...)
public abstract class ServiceUnit extends ERXGenericRecord
public class ServiceProvider extends ServiceUnit
public class ServiceConsumer extends ServiceUnit
public class User extends ERXGenericRecord
User <<-> ServiceUnit
When you do a fetch for a User with a qualifier like
User.LOGIN.is("foo").and(User.SERVICE_UNIT.dot(ServiceUnit.NAME).is
("provider"))
the SQL generated by EOF will only use the table for the abstract
entity ServiceUnit in the where clause and ignore the tables of the
concrete entites:
<com.webobjects.jdbcadaptor._FrontBasePlugIn$FrontbaseExpression:
"SELECT t0."id", t0."login", t0."serviceUnitID" FROM "User" t0 INNER
JOIN "ServiceUnit" T1 ON t0."serviceUnitID" = T1."id" WHERE
(t0."login" = 'foo' AND T1."name" = 'provider')">
In this case you will need to first fetch the ServiceUnit and then
pass it in the qualifier.
Perhaps that's because EOF is confused by the mis-modelling.
Timo
Am 07.09.2009 um 01:18 schrieb Jon Nolan:
I haven't used inheritance in years. My experience was that the
hassles you faced far outweighed the benefits of elegance of design.
I now have a project which begs for it. What say you? Do you use
inheritance or is my gut feeling correct in telling me to keep on
staying away?
with regards,
--
Lachlan Deck
_______________________________________________
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