FAQ
Hello!


I am trying to model a list of heterogeneous entities by having a
ListItem table where the list item entity is able to point to an
arbitrary entity (Person, Computer, URL, Movie, etc).


I don't want to use single-table inheritance natively supported by
Cayenne because of big database size overheads (the entities are
drastically different from one another). In fact I don't necessarily
want to use inheritance at all (PersonListItem, ComputerListItem,
etc), but this seems to be the only option in Cayenne to model such a
list.


I've read Mike Kienenberger's article
(http://cwiki.apache.org/CAY/compositeverticalinheritance.html) about
simulation of vertical inheritance in Cayenne and found that it might
be acceptable for my case.

But I am having problems generating classes from the velocity template

- Скрыть цитируемый текст -
given in the article, although I've used code generator parameters
recommended in article.


It seems the parser fails to parse ${objEntity.getClientSuperClassName()},

${anObjEntity.getClientClassName()}, although other methods/attributes
of "objEntity", "entityUtils", "stringUtils", "importUtils" are parsed
correctly.


I've tried with Cayenne 2.0.4, Cayenne 3.0M4.


Thank you,

Andrey Strib.

Search Discussions

  • Malcolm Edgar at Jul 10, 2008 at 10:53 am
    For this type of design a couple of alternatives are:

    #1 - Composition Design

    Follow the object composition pattern, i.e. an object has a, instead
    of an object is a. So your base entity could maintain a type column
    and then foreign key relationships to other tables, dependent upon
    what type of entityit is.

    #2 - Metadata Design

    This pattern has a header table, with common object header
    information, and a link to a table of name / value pairs which
    represent the object attributes. This can be cut a number of ways.
    You can have a table which defines object attribute types or meta
    data, and then have an join table between the attribute type (meta
    data) and object table, which contains the objects attribute value.

    Both of these design's have pros and cons. Metadata Design's are very
    flexible and can be remodelled at runtime, but they usuallly done
    scale well and are difficult to write reports against. The
    composition based design is pretty well the flip side of the Metadata
    design.

    regards Malcolm Edgar
    On Thu, Jul 10, 2008 at 8:03 PM, ihawk ihawker wrote:
    Hello!


    I am trying to model a list of heterogeneous entities by having a
    ListItem table where the list item entity is able to point to an
    arbitrary entity (Person, Computer, URL, Movie, etc).


    I don't want to use single-table inheritance natively supported by
    Cayenne because of big database size overheads (the entities are
    drastically different from one another). In fact I don't necessarily
    want to use inheritance at all (PersonListItem, ComputerListItem,
    etc), but this seems to be the only option in Cayenne to model such a
    list.


    I've read Mike Kienenberger's article
    (http://cwiki.apache.org/CAY/compositeverticalinheritance.html) about
    simulation of vertical inheritance in Cayenne and found that it might
    be acceptable for my case.

    But I am having problems generating classes from the velocity template

    - Скрыть цитируемый текст -
    given in the article, although I've used code generator parameters
    recommended in article.


    It seems the parser fails to parse ${objEntity.getClientSuperClassName()},

    ${anObjEntity.getClientClassName()}, although other methods/attributes
    of "objEntity", "entityUtils", "stringUtils", "importUtils" are parsed
    correctly.


    I've tried with Cayenne 2.0.4, Cayenne 3.0M4.


    Thank you,

    Andrey Strib.
  • Ihawk ihawker at Jul 10, 2008 at 2:38 pm
    Thank you for the answer. As I understand I follow Composition Design, but
    still have problems with implementing inheritance...

    It seems my first message was badly formatted.
    So I'll copy it in this message again:

    -----------------
    Hello!


    I am trying to model a list of heterogeneous entities by having a
    ListItem table where the list item entity is able to point to an
    arbitrary entity (Person, Computer, URL, Movie, etc).


    I don't want to use single-table inheritance natively supported by
    Cayenne because of big database size overheads (the entities are
    drastically different from one another). In fact I don't necessarily
    want to use inheritance at all (PersonListItem, ComputerListItem,
    etc), but this seems to be the only option in Cayenne to model such a
    list.


    I've read Mike Kienenberger's article
    (http://cwiki.apache.org/CAY/compositeverticalinheritance.html) about
    simulation of vertical inheritance in Cayenne and found that it might
    be acceptable for my case.

    But I am having problems generating classes from the velocity template
    given in the article, although I've used code generator parameters
    recommended in article.


    It seems the parser fails to parse ${objEntity.getClientSuperClassName()},
    ${anObjEntity.getClientClassName()}, although other methods/attributes
    of "objEntity", "entityUtils", "stringUtils", "importUtils" are parsed
    correctly.


    I've tried with Cayenne 2.0.4, Cayenne 3.0M4.


    Thank you,

    Andrey Strib.
  • Mike Kienenberger at Jul 10, 2008 at 4:25 pm
    As Malcolm said, I wouldn't model this with inheritance.

    I've done something similar, probably using what Malcolm called
    Composition Design.
    I used a LOG table to track field-level changes in my application:

    ColumnName Type Name Size Scale Nullable AutoIncrement Type
    FIELD_NAME VARCHAR2 64 0 Not Null false 12
    FOREIGN_RECORD_KEY NUMBER 22 -127 Nullable false 2
    LOG_ID NUMBER 22 -127 Not Null false 2
    MODIFICATION_DATE TIMESTAMP 11 1 Not Null false 93
    NEW_VALUE VARCHAR2 255 0 Nullable false 12
    OLD_VALUE VARCHAR2 255 0 Nullable false 12
    TABLE_NAME VARCHAR2 32 0 Not Null false 12

    I then created a relationship between this table and every table in my
    model. This can work well for write-only tables, but doing queries
    on it requires knowing the table name/field_name.

    One maintenance issue is that you have to update your ListItem model
    every time you add or remove a new kind of item.

    As for the specific issue with ${objEntity.getClientSuperClassName()}
    and ${anObjEntity.getClientClassName()}, you have to manually put the
    inheritance superclass name into those fields. I was overloading the
    meaning of those fields, and there may be problems doing this in 3.0
    now that ROP is more fully implemented. I would think it would still
    be workable under 2.0, though.
    On 7/10/08, ihawk ihawker wrote:
    Hello!


    I am trying to model a list of heterogeneous entities by having a
    ListItem table where the list item entity is able to point to an
    arbitrary entity (Person, Computer, URL, Movie, etc).


    I don't want to use single-table inheritance natively supported by
    Cayenne because of big database size overheads (the entities are
    drastically different from one another). In fact I don't necessarily
    want to use inheritance at all (PersonListItem, ComputerListItem,
    etc), but this seems to be the only option in Cayenne to model such a
    list.


    I've read Mike Kienenberger's article
    (http://cwiki.apache.org/CAY/compositeverticalinheritance.html) about
    simulation of vertical inheritance in Cayenne and found that it might
    be acceptable for my case.

    But I am having problems generating classes from the velocity template

    - Скрыть цитируемый текст -
    given in the article, although I've used code generator parameters
    recommended in article.


    It seems the parser fails to parse ${objEntity.getClientSuperClassName()},

    ${anObjEntity.getClientClassName()}, although other methods/attributes
    of "objEntity", "entityUtils", "stringUtils", "importUtils" are parsed
    correctly.


    I've tried with Cayenne 2.0.4, Cayenne 3.0M4.


    Thank you,

    Andrey Strib.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedJul 10, '08 at 10:03a
activeJul 10, '08 at 4:25p
posts4
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase