Re: Abstract Entities [Was: Modelling improvements: inheritance + interfacing (Draft)]

From: Craig L Russell (Craig.Russel..un.COM)
Date: Thu May 31 2007 - 02:59:25 EDT

  • Next message: Aristedes Maniatis: "Re: Abstract Entities [Was: Modelling improvements: inheritance + interfacing (Draft)]"

    Hi Aristedes,

    On May 30, 2007, at 10:09 PM, Aristedes Maniatis wrote:

    >
    > On 31/05/2007, at 1:03 PM, Craig L Russell wrote:
    >
    >> While it might be possible theoretically to define a different
    >> column in the database to be used as the association column to
    >> join rows of a subclass and a superclass table, by far the most
    >> common and most understandable way to map inheritance is to simply
    >> assume that the primary key of both tables is the same and that
    >> the id field in the class contains the value to be used for both
    >> primary keys. The direction of the foreign key constraint should
    >> indicate which is the subclass.
    >
    > Yes, 99% of the time this is correct. However, if we want to
    > support compound primary keys there is a need to describe how the
    > columns in the subclass map to the columns in the superclass.

    If it really is an inheritance relationship and not a one-one or one-
    many relationship, the compound primary keys should also correspond
    exactly.

    > That way Cayenne can populate them both correctly. Our original
    > plan was to use an object relationship description in the DataMap
    > to describe this pairing. The alternative is to use the names of
    > the object attributes in order to match the primary key columns to
    > each other, but something about this bothers me as an approach.

    The most common case I've seen has a foreign key constraint defined
    on the primary key columns of the subclass table to the corresponding
    primary key columns of the superclass table.
    >
    > Also, as Lachlan points out, this means that we don't get to
    > specific nullify, cascade, etc delete rules. If you have a concrete
    > superclass, you may wish to nullify the relationship when deleting
    > the subclass record. Naturally if the superclass is abstract this
    > is not allowed. But specifying the objrelationship explicitly
    > allows us to put these rules somewhere and remove any ambiguity
    > from compound key relationships.

    This seems like an implementation detail (which I am very obviously
    not competent to comment on).

    Regards,

    Craig
    >
    > Ari
    >
    >
    >
    > -------------------------->
    > Aristedes Maniatis
    > phone +61 2 9660 9700
    > PGP fingerprint 08 57 20 4B 80 69 59 E2 A9 BF 2D 48 C2 20 0C C8
    >
    >

    Craig Russell
    Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
    408 276-5638 mailto:Craig.Russel..un.com
    P.S. A good JDO? O, Gasp!





    This archive was generated by hypermail 2.0.0 : Thu May 31 2007 - 12:00:01 EDT