On Wed, 9 Jun 2004, Bradford Pielech wrote:
> Hello:
>
> I have a class that acts like a standard DAG node, i.e. it has multiple
> parents and children that are each DAG nodes. I am using the Xdoclet
> module to create the repository file and torque to create SQL and
> database. I am representing the parent and children relationships using an
> indirection table. My problem is this- the XDoclet module incorrectly
> generates the fk-pointing-to-element-class value. Below is the generated
> mapping file and corresponding java source. Notice that the
> fk-pointing-to-element-class element for the children collection should
> have a value of "child_id".
> If I manually change this value, then the mapping and sql are correct, and
> my program behaves as I expect.
>
> Mapping snippet:
> ----------------------------
> <class-descriptor
> class="SimpleDAGNode"
> table="effect"
> >
> <field-descriptor
> name="ID"
> column="ebo_id"
> jdbc-type="VARCHAR"
> primarykey="true"
> length="35"
> >
> </field-descriptor>
> <collection-descriptor
> name="children"
> element-class-ref="SimpleDAGNode"
> indirection-table="parent_children_table"
> auto-retrieve="true"
> auto-update="true"
> auto-delete="true"
> >
> <fk-pointing-to-this-class column="parent_id"/>
> <fk-pointing-to-element-class column="parent_id"/>
> </collection-descriptor>
>
> <collection-descriptor
> name="parents"
> element-class-ref="SimpleDAGNode"
> indirection-table="parent_children_table"
> auto-retrieve="true"
> auto-update="true"
> auto-delete="true"
> >
> <fk-pointing-to-this-class column="child_id"/>
> <fk-pointing-to-element-class column="parent_id"/>
> </collection-descriptor>
> </class-descriptor>
> --------------------
>
> Java source:
> -----------------------------
> public class SimpleDAGNode {
>
> /**
> * @ojb.collection
> element-class-ref="com.alphatech.ebo.datamodels.SimpleDAGNode"
> * auto-retrieve="true"
> * auto-update="true"
> * auto-delete="true"
> * indirection-table="parent_children_table"
> * foreignkey="parent_id"
> */
> protected List children;
>
> /**
> * @ojb.field primarykey="true"
> * column="ebo_id"
> * jdbc-type="VARCHAR"
> * length="35"
> */
> protected String ID;
>
> /**
> * @ojb.collection
> element-class-ref="com.alphatech.ebo.datamodels.SimpleDAGNode"
> * auto-retrieve="true"
> * auto-update="true"
> * auto-delete="true"
> * indirection-table="parent_children_table"
> * foreignkey="child_id"
> */
> protected List parents;
> ------------------------------------
>
> If I switch the order that parents and children are declared in the java
> file, the problem happens with parents, not children. Thus, it appears
> something is amiss in the XDoclet.
Well, its not exactly a bug. Since you didn't specify an inverse foreign
key, the XDoclet module will use the foreignkey of the first collection in
the element class that specifies the same indirection table. Only it
currently won't check whether thats the same collection (which I'll fix).
However I think in your case you should specify the inverse foreignkey
anyway. If (for whatever reason) you decide to add a third collection
right that points to the same class (e.g. neighbors) at the beginning of
the class then you will get the same problem again.
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]