cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aristedes Maniatis <>
Subject Re: abstract entities, inheritance, etc.
Date Thu, 23 Apr 2009 23:32:00 GMT

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



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

View raw message