I have a self referential table that I am mapping with kodo jdo 4 (supplied from weblogic server 10.3.4.) The code I have will get through the enhancer, but when I try to use it I get the error:
<openjpa-1.1.1-SNAPSHOT-r422266:965591 fatal user error> kodo.jdo.FatalUserException: Missing table name for field "com.[...].jdo.Branch.branches". This field cannot reside in the owning class table.
at org.apache.openjpa.jdbc.meta.FieldMapping.mapJoin(FieldMapping.java:529)
the table is:
CREATE TABLE branch
(
id VARCHAR2(10) NOT NULL,
parentId VARCHAR2(10) NOT NULL,
[other fields deleted ...]
CONSTRAINT branch_pk PRIMARY KEY(id),
CONSTRAINT branch_fk_parent FOREIGN KEY(parentId) REFERENCES branch(id)
);
the class is :
public class Branch implements MenuPart, Serializable
{
private Branch parent;
private Set<Branch> branches = new HashSet<Branch> ();
private String id;
private Set<Leaf> leafs = new HashSet<Leaf> ();
private long ordering;
private String title;
//methods removed.
}
the package.jdo file is:
<class name="Branch" objectid-class="BranchId" table="SCHEMA.BRANCH">
<version strategy="none"/>
<field name="parent" table="SCHEMA.BRANCH">
<column name="SCHEMA.BRANCH.PARENTID" target="ID" />
</field>
<field name="branches" table="SCHEMA.BRANCH" >
<collection element-type="Branch"/>
<join>
<column name="SCHEMA.BRANCH.PARENTID" target="ID" />
</join>
</field>
<field name="id" column="ID" primary-key="true"/>
<field name="leafs" table="SCHEMA.LEAF">
<collection element-type="Leaf"/>
<join>
<column name="ID" target="BRANCHID" />
</join>
</field>
<field name="ordering" column="ORDERING"/>
<field name="title" column="TITLE"/>
</class>
I have gotten the functionality to work in kodo jdo 3.4 but now the syntax is different and the friendly manual isn’t that helpful that I can find.
here is what finally worked
Apparently all it needed was a mapped-by=”parent” attribute.