Mapping an Object Hierarchy to a Relational Database?

Discussions

General J2EE: Mapping an Object Hierarchy to a Relational Database?

  1. I am attempting to define a process to map an Object Hierarchy to a Relational database (Oracle) that is compatible with J2EE CMP Entity Beans. It doesn't seem to be an easy task.

    Has anyone done this? or know of any white paper that resolves the implementation issues?

    Cheers,
    Tim.
  2. are you asking if you have inheritance how you map it to rdbms? the ways i am familiar with are:

    * single table
    * root/leaf
    * multiple tables

    e.g.,

    classA has attribute A
    classB extends ClassA and adds attribute B
    classC extends ClassA and adds attribute C

    single table:
    table T would have columns A, B, C (corresponding to the attributes of classA, classB, classC) and a discriminator column to identify the type (what class is the row).

    root/leaf:
    table T_1 would have column A and discriminator column
    table T_2 would have column B and fk to table T_1
    table T_3 would have column C and fk to table T_1

    so classA maps to T_1
    classB maps to T_1 join T_2
    classC maps to T_1 join T_3

    multiple tables:
    classA maps to T
    classB maps to T_1
    classC maps to T_2
    T, T_1 and T_2 are completely unrelated

    each approach has some pro/cons, like whether it'll be normalized, overhead of join.

    with respect to entity beans...inheritance in ejb is a tricky subject, as component inheritance is not supported in the spec, along you can do it. your app server's cmp tool will have to support this...for more detail i would suggest you download toplink or cocobase...i know for sure toplink supports this type of mapping and i would assume cocobase also does.

    hope that helps.

    --
    Tinou
    www.tinou.com

  3. There are three possible solutions, you can have for
    mapping the object hierarchy into the database, Horizontal,
    Vertical and Collapsed. In horizontal, number of tables required is based on the number of leaf nodes in the hierarchy. In Vertical mapping, for each object in the
    hierarchy, there is a corresponding table. In Collapsed
    approach, all the objects are stored in a single table.
    Depending upon your application environment (complexity
    involved in object retrieval) you can choose on approach
    that best suits you.

    In EJB2.0, the local bean contract supports inheritance hierarchy. You can also use FrontierSuite from
    ObjectFrontier as a platfrom for developing EJB
    (includes support for EJB2.0) application. FrontierSuite
    Fusion Builder provides you an environment to map your
    object hierarchy into Vertical or Horizontal approach.

    FrontierSuite provides a sophisticated runtime
    engine that can easily be plugged into any application
    server to provide CMP.