No guarantee that it won't end up being just another mailing list discussion with no code committed, but giving it another shot. Myself and Dzmitry Rusak (he hasn't participated on this list, but hopefully he will over time; he is the guy who developed DataMap generator templates that create named query methods) have been looking at the CAY-795 Jira and Marcin's patch to implement horizontal inheritance, with the goal to advance this task further.

We discussed ORM inheritance in general, possible approaches to the mapping, and just touched a bit on the runtime. For me it was helpful to realize that there is no spoon :-) For all the talk about single- table, vertical and horizontal inheritance, Cayenne runtime will end up dealing with a hybrid case of any possible combination of the above in each given hierarchy. So the terminology will be different when we get to nuts and bolts of the mapping: ObjEntity to DbEntity mapping; ObjEntity qualifier; ObjAttribute overrides in subclasses. These are the three pieces that allow inheritance to happen in the mapping (all 3 types of inheritance).

Let me come back to this in a moment... Now a note on implementation. I'd like to follow an approach that proved itself with other features:

(1) implement new features needed in the mapping layer (including save/ load) (2) implement Modeler support for that (although that can be postponed till after #3 as to avoid early exposing of the incomplete features to the end users) (3) implement runtime support for select / select relationship / insert / update / delete, with unit tests
(4) do #3 for ROP

So essentially this is going layer by layer instead of cutting across, and when we get to runtime parts, we already have a mapping framework to create the test cases. The plan is to bypass Marcin's patch (that has code across the layers) and start with (1) and (2). For #1, some preliminary work has been done by Ari and Marcin (CAY-794), so now we need to relax some mapping restrictions (coming from assuming that all inheritance == single table inheritance) and introduce a new concept of ObjAttribute overrides. It exists in JPA (for the same purpose of mapping inheritance), and so far has been absent from Cayenne (except for the embeddables that are still somewhat hidden from the public view by the absent Modeler support).

Once we have that, we can move to the runtime pieces... That's where the real fun starts... Consider that to fetch superclass in case of horizontal inheritance, we'd need to do separate queries on each subclass on the tree, and then combine the result in an in-memory "union" and then apply in-memory sort ordering on top of that :-)

Andrus

Reply via email to