Problem with self-join-relationship

From: Jens Mayer (jens.mayer..mx.de)
Date: Mon Aug 20 2007 - 16:19:24 EDT

  • Next message: Mike Kienenberger: "Re: Problem with self-join-relationship"

    Hi,

    I'm trying to build a tree-like structure based on data in my db.

    My table TMP_TRANSEDIT has a relationship to itself:

    TMPTRANSEDIT_ID NUMBER(10) is the PK ... and
    TMPTRANSEDIT_TMPTRANSEDIT_ID NUMBER(10) is used for the relationship to
    the parent.

    The tabledata is inserted by two queries, first the insert-query for the
    rows and afterwards an update-query to set the parent/child relationship.
    After that, all modifications are committed.

    Now I'm querying each node (in the same DataContext I used for the
    inserts/updates), starting with the root-tier
    (TMPTRANSEDIT_TMPTRANSEDIT_ID is null)

    Upto this point all is working fine.

    But now I'm trying to read the childs for each rootnode (triggered by
    the user expanding the related node in the GUI). I'm using the
    ObjectRelationship toTmpTranseditArray which should contain the
    child-DataObjects for each given rootnode. But the List returned by the
    getToTmpTranseditArray()-Method is empty. The logging shows that after
    the rootnodes-query there is no further query performed.

    Am I wrong with my approach? Or do I have to consider something special
    to Cayenne? One possible solution is to query the childs for each node
    manually by using a new SelectQuery, but this doesn't seem to be the
    best practice to me...

    Below I added the code of the child-query and the mapping from the
    map.xml concerning the TMP_TRANSEDIT-Table.

    I'm using Cayenne 2.0.2, JDK 1.5.0_10 and Oracle 10.2.0.3.0.

    Thanks in advance,

    Jens

    This the code of my child-query:

    public boolean hasChildren(Object element) {
       TmpTransedit trans = (TmpTransedit)element;
       List children = trans.getTmpTranseditArray();
       int size = children.size();
       return size>0;
    }

    This is the mapping for the DB-Table:
    <db-entity name="TMP_TRANSEDIT">
       <db-attribute name="ERROR_CODE" type="INTEGER" length="5"/>
       <db-attribute name="IDENT_KEY" type="VARCHAR" length="30"/>
       <db-attribute name="IDENT_NAME" type="VARCHAR" length="40"/>
       <db-attribute name="KNZ_REAKTION" type="VARCHAR" length="1"/>
       <db-attribute name="MACHINE_NAME" type="VARCHAR" length="50"/>
       <db-attribute name="SATZART" type="VARCHAR" isMandatory="true"
    length="20"/>
       <db-attribute name="SENDATEI_SENDATEI_ID" type="INTEGER" length="10"/>
       <db-attribute name="TMPTRANSEDIT_ID" type="INTEGER"
    isPrimaryKey="true" isMandatory="true" length="10"/>
       <db-attribute name="TMPTRANSEDIT_TMPTRANSEDIT_ID" type="INTEGER"
    length="10"/>
       <db-attribute name="USER_NAME" type="VARCHAR" length="50"/>
       <db-key-generator>
         <db-generator-type>ORACLE</db-generator-type>
         <db-generator-name>TMPTRANSEDIT_SEQ</db-generator-name>
    <db-key-cache-size>1</db-key-cache-size>
       </db-key-generator>
    </db-entity>

    ... the ObjectEntity
    <obj-entity name="TmpTransedit"
    className="de.edeka.ebus.dc.db.TmpTransedit" dbEntityName="TMP_TRANSEDIT">
       <obj-attribute name="errorCode" type="java.lang.Integer"
    db-attribute-path="ERROR_CODE"/>
       <obj-attribute name="identKey" type="java.lang.String"
    db-attribute-path="IDENT_KEY"/>
       <obj-attribute name="identName" type="java.lang.String"
    db-attribute-path="IDENT_NAME"/>
       <obj-attribute name="knzReaktion" type="java.lang.String"
    db-attribute-path="KNZ_REAKTION"/>
       <obj-attribute name="machineName" type="java.lang.String"
    db-attribute-path="MACHINE_NAME"/>
       <obj-attribute name="satzart" type="java.lang.String"
    db-attribute-path="SATZART"/>
       <obj-attribute name="userName" type="java.lang.String"
    db-attribute-path="USER_NAME"/>
    </obj-entity>

    ... the db-relationships
    <db-relationship name="tmpTranseditArray" source="TMP_TRANSEDIT"
    target="TMP_TRANSEDIT" toMany="true">
       <db-attribute-pair source="TMPTRANSEDIT_ID"
    target="TMPTRANSEDIT_TMPTRANSEDIT_ID"/>
    </db-relationship>

    <db-relationship name="toSenDateien" source="TMP_TRANSEDIT"
    target="SEN_DATEIEN" toMany="false">
       <db-attribute-pair source="SENDATEI_SENDATEI_ID" target="SENDATEI_ID"/>
    </db-relationship>

    <db-relationship name="toTmpAttreditArray" source="TMP_TRANSEDIT"
    target="TMP_ATTREDIT" toMany="true">
       <db-attribute-pair source="TMPTRANSEDIT_ID"
    target="TMPTRANSEDIT_TMPTRANSEDIT_ID"/>
    </db-relationship>

    <db-relationship name="toTmpTransedit" source="TMP_TRANSEDIT"
    target="TMP_TRANSEDIT" toMany="false">
       <db-attribute-pair source="TMPTRANSEDIT_TMPTRANSEDIT_ID"
    target="TMPTRANSEDIT_ID"/>
    </db-relationship>

    ... and the obj-relationships
    <obj-relationship name="tmpTranseditArray" source="TmpTransedit"
    target="TmpTransedit" db-relationship-path="tmpTranseditArray"/>
    <obj-relationship name="toDatei" source="TmpTransedit" target="Datei"
    db-relationship-path="toSenDateien"/>
    <obj-relationship name="toTmpAttreditArray" source="TmpTransedit"
    target="TmpAttredit" db-relationship-path="toTmpAttreditArray"/>
    <obj-relationship name="toTmpTransedit" source="TmpTransedit"
    target="TmpTransedit" db-relationship-path="toTmpTransedit"/>



    This archive was generated by hypermail 2.0.0 : Mon Aug 20 2007 - 16:20:01 EDT