Hi again,

> > I'm right now trying to create the mapping for 2 class I've developped:
> >   - A contains a Collection of class B
> >   - B doesn't have any relation back to A
> >
> > With my current understanding of OJB, I'll need to create in B a
> > reference
> > back to A to be able to make the mapping (using an inverse-foreignkey
> > element). Is that right ? If yes why ?
>
> What you need is not a full reference object pointing back to A, but an
> attribute that holds the foreign attribute.
>
> If the table A has a Primary key A_ID then the B table must contain a
> column FK_A_ID to allow the RDBMS to manage the foreign constraints.
>
> OJB simply parallels the foreign mechanisms of relational databases here
>   and thus you need attributes in your persistent classes to hold
> primary- and foreign-key data.

I still have some problem to understand this.

So I have 2 tables:
 - TABLE_A containing a field A_ID
 - TABLE_B containing a field B_ID and a field FK_A_ID

I also have 2 classes for persistence:
 - A containing an attribute collectionOfBs and another atribute id
 - B containing an attribute id

In this case, I think I _need_ to add an extra attribute to the B classes
idOfA, so I can make the mapping:

<class-descriptor class="A"
    table="TABLE_A">
  <field-descriptor id="1"
      name="id"
      column="A_ID"
      jdbc-type="INTEGER"
      primarykey="true"
      autoincrement="true"/>
  <collection-descriptor
      name="collectionOfBs"
      element-class-ref="B">
    <inverse-foreignkey field-id-ref="2"/>
  </collection-descriptor>
</class-descriptor>

<class-descriptor class="B"
    table="TABLE_B">
  <field-descriptor id="1"
      name="id"
      column="B_ID"
      jdbc-type="INTEGER"
      primarykey="true"
      autoincrement="true"/>
  <field-descriptor id="2"
      name="idOfA"
      column="FK_A_ID"
      jdbc-type="INTEGER"
      primarykey="true"
      autoincrement="true"/>
</class-descriptor>

In my case, there is really no need for the idOfA attribute in B. B objects
are aggregated to A object.

I do not think that there is a need for this back reference.

Cheerio,
    Guillaume




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to