What is the syntax of package.jdo file for a self referential table

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.

Answers


Perhaps its objecting to you defining the join-table for that relation to be the table for the class itself (which is obviously wrong).

Obviously Kodo is not fully JDO-compliant, and is dead as a project, so if you hit issues then you've got problems ...


Can you try

<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"/>
        <extension vendor-name="kodo" key="inverse-owner" value="parent"/>
    </field>
    <field name="id" column="ID" primary-key="true"/>
</class>

here is what finally worked

    <class name="Branch" objectid-class="BranchId" table="EBIGP.BRANCH">
        <version strategy="none"/>
        <field name="parent">
            <column name="EBIGP.BRANCH.PARENTID" target="ID" />
        </field>
        <field name="branches" mapped-by="parent" />
        <field name="id" column="ID" primary-key="true"/>
        <field name="leafs" default-fetch-group="true">
            <collection element-type="Leaf"/>
            <element column="BRANCHID"/>
        </field>
        <field name="ordering" column="ORDERING"/>
        <field name="title" column="TITLE"/>
    </class>

Apparently all it needed was a mapped-by="parent" attribute.


Need Your Help

How long do the magento session files need to be kept?

php session magento memcached

I have a customer who's magento session files are quickly growing out of control. We are purging them once a week, but it seems that it may need to be more frequent.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.