RE: Single table inheritance

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Oct 13 2004 - 15:00:08 EDT

  • Next message: Mikaël Cluseau: "Table inheritance (WAS Re: Single table inheritance)"

    Let me clarify the likely source of confusion. PostgreSQL supports
    inheritance at the DB level:
    http://www3.ca.postgresql.org/docs/current/static/tutorial-inheritance.html
    This is one of the cool features of PostgreSQL (and I only learned about
    it today myself). But to the best of my knowledge it is not a part of SQL
    standard, and I am not aware of other DB engines supporting that. Also
    JDBC doesn't support any metadata about Postgres table inheritance (unless
    there are some Postgres driver-specific extensions?), and thus
    reverese-engineering procedure treats those tables as independent from
    each other.

    So from Cayenne perspective this type of mapping won't be "single table"
    anymore, and you should probably keep the default created Java mapping.

    Andrus

    > My usual disclaimer: I haven't done this yet. :-)
    >
    > You say you created *three* tables? Single-table inheritance will only
    > work within one table. It will basically give you different views and
    > classes into a single table. This is why when you set the "Inheritance"
    > pulldown, it switches the "Table/View" pulldown automatically for you
    > (it locks you into that table).
    >
    > You'll also notice a "Qualifier" text field under the ObjEntity
    > Configuration. This is where you enter a Cayenne qualifier for that
    > entity, which is how Cayenne determines which class to instantiate.
    >
    > For example, with one table (BaseTable), but two entities mapped into
    > it:
    >
    > BaseTable DbEntity contains:
    >
    > primaryKey (integer, pk, mandatory)
    > flag (integer, mandatory)
    > value1 (integer)
    > value2 (integer)
    >
    > BaseTable ObjEntity should be synched up with DbEntity.
    >
    > Create an Entity1 ObjEntity. Inherit from BaseTable. For qualifier,
    > make it "flag = 1". Under attributes, delete "value2" row.
    >
    > Create an Entity2 ObjEntity. Inherit from BaseTable. For qualifier,
    > make it "flag = 2". Under attributes, delete "value1" row.
    >
    > You now have 3 entities, but only 1 table. When you do queries from the
    > database, if the flag is equal to 1, it'll create an instance of Entity1
    > for you, even though BaseTable and Entity2 share the same tablespace.
    > You can filter which attributes show up in each entity and, maybe more
    > importantly, have separate business logic/derived values for each. Of
    > course, if you actually need BaseTable entities, set it's qualifier to
    > "flag = 0". Be sure to initialize your flags correctly, too ...
    >
    > Hope that helps.
    >
    > /dev/mrg
    >
    >
    > -----Original Message-----
    > From: Mikaël Cluseau [mailto:nwr..wrk.dyndns.org]
    > Sent: Wednesday, October 13, 2004 11:44 AM
    > To: cayenne-use..bjectstyle.org
    > Subject: Single table inheritance
    >
    >
    > Heelo people,
    >
    > I see that Cayenne support single table inheritance but I realy don't
    > understand how it work (CAY-24 feature request).
    >
    > I created a simple test with 3 tables under PostgreSQL :
    > * Header, with a column "id" (serial, primary key) ;
    > * Table1, inherits Header and adds a column "name" ;
    > * Table1, inherits Header and adds a column "price" ;
    >
    > Then, I reeginered the schema using the modeler and generated the
    > classes. No inheritance between Header, Table1 or Table2. When I try to
    > set the "Inheritance" ObjEntity Configuration of Table1 it overides
    > "Table/view" to Header.
    >
    > DerivedEntities don't seems to be done for that, too, and some googleing
    > didn't shown me anything useful.
    >
    > Can someone help me please ?
    >
    > Thanks,
    > Mikael.



    This archive was generated by hypermail 2.0.0 : Wed Oct 13 2004 - 15:00:10 EDT