Dave,

Ok, I see the misunderstanding now.  I thought you were talking about the
jbosscmp-jdbc.xml file and you were talking about the ejb-jar.xml file.  You
are correct in that a single relation can only have one cmr field on each
side of the relationship. From my perspective these are object layer cmr
fields and not relational level foreign keys.

To specify how a relationship maps, you need to add a relationships section
to the jbosscmp-jdbc.xml file.

<relationships>
<ejb-relation>
    <ejb-relation-name>Order-OrderDetail</ejb-relation-name>
    <foreign-key-mapping>
        <ejb-relationship-role>

<ejb-relationship-role-name>Order-has-OrderDetail</ejb-relationship-role-nam
e>

            <foreign-key-fields/>

        </ejb-relationship-role>

        <ejb-relationship-role>
            <ejb-relationship-role-name>OrderDetail-
belongsTo-Order</ejb-relationship-role-name>

            <foreign-key-fields>
                <foreign-key-field>
                    <field-name>order_oid</field-name>
                    <column-name>order_oid</column-name>
                </foreign-key-field>
            </foreign-key-fields>

        </ejb-relationship-role>
    </foreign-key-mapping>
</ejb-relation>
</relationships>

I'm not sure that this will work.  The code may try to create a table with 2
order_oid columns because you trying to reuse a column mapped to a cmp field
to store a relation foreign key.  You may need to create the table by hand.
I need to check this, because I think it will be a common mapping.

I'd also like to take a moment to explain why the foreign key field is
generated the way it is.

I can't just a cmp field has the same name as the pk related ejb becasue of
the case of a self related entity such as an employee/manager relationship
in the employee object. I always have to prepend the ejb name of the related
ejb to the fk, because it is common to have all beans to have a generic pk
name such as oid (I do this).

I hope this helps you,

-dain


_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to