Re: abstract entities, inheritance, etc.

From: Aristedes Maniatis (ar..sh.com.au)
Date: Thu Apr 23 2009 - 19:32:00 EDT

  • Next message: Robert Zeigler: "Re: abstract entities, inheritance, etc."

    On 24/04/2009, at 9:17 AM, Robert Zeigler wrote:

    > So, I was playing around a bit with the "is abstract" flag on
    > abstract entities.
    > I confess that it didn't quite work the way I thought it would.
    > For one, the superclass was abstract, but not the subclass.

    That is the common situation when you want horizontal inheritance. [1]

    > I went ahead and made the subclass abstract. Which raises the
    > second issue. I have two obj entities entities extending the
    > "abstract" superclass, using a single discriminator column. I went
    > to query the base class (ala: select e from Entry e), and the query
    > failed, due to the inability to instantiate an instance of Entry.
    > Evidently, cayenne is trying to instantiate all of the subclasses
    > instances as instances of the superclass. Shouldn't cayenne be
    > instantiating the subclasses?

    EOF has a switch for this called something like 'deep object
    resolution'. That is, when you query Artist.class, should you get back
    a list of Painter.class, Photographer.class, etc object (as you are
    expecting), or get back a list of Artist objects. Each can be useful
    in different situations, particularly since just returning Artist
    objects means less work for the database (fewer JOINs).

    Obviously if your query was for Painter.class then you will only get
    Painter objects back.

    > Put another way, what is the technical reason that cayenne /isn't/
    > instantiating the subclasses as instances of the subclasses? Given
    > the potential of polymorphism, it seems like instantiating as the
    > superclass, even if the superclass is concrete, is incorrect
    > behavior? Just trying to clarify, here. I'll be digging through the
    > code to try to understand the specifics of how cayenne handles
    > inheritance, but, any pointers appreciated.

    I think ultimately we need both behaviours.

    > Robert

    Ari

    [1] http://cayenne.apache.org/doc/inheritance-overview.html

    -------------------------->
    ish
    http://www.ish.com.au
    Level 1, 30 Wilson Street Newtown 2042 Australia
    phone +61 2 9550 5001 fax +61 2 9550 4001
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A



    This archive was generated by hypermail 2.0.0 : Thu Apr 23 2009 - 19:32:34 EDT