I didn't do One-To-Many Bi-Directional in my project but I think it would look something like this if you assumed the following: the example I posted before  is modified to make it a One-to-Many rel so that each Customer can have many accounts but each account is only associated with a single customer.

<relationships>

                <ejb-relation>
                  <ejb-relation-name>Account-Customers</ejb-relation-name>
                  

                   <ejb-relationship-role>
                      <relationship-role-source>
                         <ejb-name>Account</ejb-name>
                       </relationship-role-source>
                       <cmr-field>
                         <cmr-field-name>customers</cmr-field-name>
                       </cmr-field>
                       <role-mapping>
                       <cmr-field-mapping>
                       <key-column>accid</key-column>
                        <foreign-key-column>accid</foreign-key-column>
                       </cmr-field-mapping>
                     </role-mapping>
                  </ejb-relationship-role>

                   <ejb-relationship-role>
                    <relationship-role-source>
                       <ejb-name>Customer</ejb-name>
                    </relationship-role-source>
                    <cmr-field>
                       <cmr-field-name>account</cmr-field-name>
                     </cmr-field>
                     <foreign-key-column-on-source />
                     <role-mapping>
                       <cmr-field-mapping>
                       <key-column>accid</key-column>
                        <foreign-key-column>accid</foreign-key-column>
                       </cmr-field-mapping>
                     </role-mapping>
                     </ejb-relationship-role>
                 </ejb-relation>

         </relationships>


On 4/20/07, Mark Aufdencamp < mark@aufdencamp.com> wrote:
David,
 
Any chance you could cut and paste me a One-To-Many Bi-Directional example as well?  I seem to only find Un-Directional Examples in my Googling:)
 
Mark Aufdencamp
Mark@Aufdencamp.com


 
-------- Original Message --------
Subject: Re: Openejb-jar and EJB 2.1 CMR Many-Many Example
From: "David Carew" < dccarew@gmail.com>
Date: Fri, April 20, 2007 8:35 am
To: user@geronimo.apache.org

Here's a simplified version of the DB schema I used for a many to many relationship between  CMP Entity beans called Account and Customer

create table customer
(
  customerid integer not null,
  title character(3) not null,
  firstname varchar(30) not null,
  lastname  varchar(30) not null,
  pin character(4) not null,
  primary key (customerid)
);


create table account
(
   accid character(11) not null,
   balance decimal(8,2) not null,
   interest decimal(5,3),
   type varchar(60) not null,
   primary key(accid)
);


create table custacct
(
   customerid integer not null,
   accid character(11) not null,
   primary key(customerid, accid),
   foreign key(customerid) references customer ON DELETE RESTRICT,
   foreign key(accid) references account ON DELETE RESTRICT
);


Here's the corresponding snippet from my openejb-jar.xml file

  <relationships>

                <ejb-relation>
                  <ejb-relation-name>Accounts-Customers</ejb-relation-name>
                   <many-to-many-table-name>
                         custacct
                   </many-to-many-table-name>


                   < ejb-relationship-role>
                      <relationship-role-source>
                         <ejb-name>Account</ejb-name>
                       </relationship-role-source>
                       <cmr-field>
                         <cmr-field-name>customers</cmr-field-name>
             &n bsp;         </cmr-field>
                       <role-mapping>
                       <cmr-field-mapping>
                       <key-column>accid</key-column>
                        <foreign-key-column>accid</foreign-key-column>
                       </cmr-field-mapping>
        &n bsp;            </role-mapping>
                  </ejb-relationship-role>

                   <ejb-relationship-role>
                    <relationship-role-source>
                       <ejb-name>Customer</ejb-name>
                    </relationship-role-source>
                    <cmr-field >
                       <cmr-field-name>accounts</cmr-field-name>
                     </cmr-field>
                    <role-mapping>
                       <cmr-field-mapping>
                              <key-column>customerid</key-column>
                         <foreign-key-column>customerid</foreign-key-column>
                       </cmr-field-mapping>
                       </role-mapping>
                     </ejb-relationship-role>
                 </ejb-relation>

         </relationships>

On 4/20/07, Mark Aufdencamp < mark@aufdencamp.com > wrote:
Hi All,
 
I'm continuing my studies and have successfully deployed CMP Entity Beans with some rudimentary QL.  I'm now working on come container manged relationships (CMR).  I can't seem to find much documentation on the appropriate mapping of the ejb-jar relationships to the openejb-jar definitions.  Can someone provide some direction to documentation on the openejb-jar mappings.  In particulare, I'm working on a Many-To-Many relationship.  I have a 3rd NF Table structure and the Entity Beans, just need that last bit of info on the openejb-jar mappings.
 
Thanks,
 
Mark Aufdencamp