Hi Michael,
Hello
Actually I am trying to use Cayenne vertical inheritance. Some more
details on what I did :
I have followed the guide here :
http://cayenne.apache.org/doc30/modeling-vertical-inheritance.htmland with a lot of trial and error, I finally got it to insert data.
Unfortunately I cannot make the select queries to work correctly.
After some searches I found that old thread with the same problem :
http://cayenne.195.n3.nabble.com/Vertical-inheritance-td827636i20.htmlI tried the workaround from that thread but it didn't help.
In my DB, I have one root table called ELEMENT from which the tables
"FILE", "PRINCIPAL" and "PERMISSION" are inheriting.
If I create a new ELEMENT like this :
Element elem = context.newObject(Element.class);
elem.setName("test1");
elem.setDescription("test1 description");
elem.setType("ELEMENT");
Or a PRINCIPAL like this :
Principal p = context.newObject(Principal.class);
p.setPassword("password");
p.setName("principal1");
p.setDescription("principal1 description");
p.setType("PRINCIPAL");
It inserts perfectly.
If I then run through JDBC "SELECT t0.ID, t0.DESCRIPTION, t0.NAME FROM
ELEMENT t0", I get the values back.
But if I make a simple select with Cayenne like :
context.performQuery(new SelectQuery(Element.class));
It does not return anything as it is trying to use the query :
SELECT t0.ID, t0.DESCRIPTION, t0.NAME, t0.TYPE, t1.PATH, t2.PASSWORD,
t3.VALUE FROM ELEMENT t0 JOIN FILE t1 ON (t0.ID = t1.ID) JOIN
PRINCIPAL t2 ON (t0.ID = t2.ID) JOIN PERMISSION t3 ON (t0.ID = t3.ID)
The query is wrong as it is trying to join the parent table on all the
child tables at the same time.
"test1" is in no subtable and "principal1" is not in FILE or PERMISSION.
I have put the map file content there :
http://pastebin.com/KtVhDdYEDo you have any idea on what to try next to get it to work ?
2011/12/13 Michael Gentry <mgentry@masslight.net>:
Hi Mathias,
I believe you are trying to use a currently unimplemented inheritance
mechanism. Cayenne does not currently support horizontal
(multiple-table) inheritance:
http://cayenne.apache.org/doc/inheritance-overview.htmlThere are tricks you can do to make working with multiple related
tables easier (such as adding getters/setters in your subclass to
reference the parent), but you cannot currently model this behavior
automatically.
mrg
On Fri, Dec 9, 2011 at 3:00 AM, Mathias Clerc wrote:
Hello,
It seems like I have missed something in inheritance in Cayenne.
I have one main table called "Element" with fields id (PK), name and description
Another table "File" inherits from "Element" with fields ID(PK, FK on
Element.id) and path.
When I do a context.performIteratedQuery(new
SelectQuery(Element.class)) The query I see is :
SELECT t0.ID, t0.DESCRIPTION, t0.NAME, t0.TYPE, t0.ID, t0.ID, t0.PATH
FROM ELEMENT t0
I tried checking and unchecking the "To Dep PK" field for the relation in ID.
What did I miss ?