自引用表的package.jdo文件的语法是什么

时间:2011-11-30 16:01:47

标签: java oracle jdo

我有一个自我参照表,我用kodo jdo 4(从weblogic服务器10.3.4提供)映射。我的代码将通过增强器,但当我尝试使用它时,我得到错误:< / p>

<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)

表格是:

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)
);

班级是:

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.
}

package.jdo文件是:

    <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>

我已经获得了在kodo jdo 3.4中工作的功能,但现在语法不同了,友好的手册对我来说没那么有用。

3 个答案:

答案 0 :(得分:0)

也许它反对你将该关系的连接表定义为类本身的表(这显然是错误的)。

显然,Kodo并不完全符合JDO标准,并且作为一个项目已经死了,所以如果遇到问题那么你就会遇到问题......

答案 1 :(得分:0)

你能试试吗

<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>

答案 2 :(得分:0)

这是最终起作用的

    <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>

显然所需要的只是一个 mapped-by =“parent”属性。