Hi,

ABOU LINA wrote:
Hi,

i give you this sample example :

in case  A<---->B  [1:n] :
     the mapping of this bidiractional navigation is guaranted by the use of
inverse-foreignkey :

     Mapping A classe :
     ----------------------------------------------------

    <collection-descriptor
       name="allB"
       element-class-ref="B"
    >
       <inverse-foreignkey field-ref="aId"/>
    </collection-descriptor>


    Mapping B class :
    ------------------------------
      <reference-descriptor
         name="a"
         class-ref="A"
      >
         <foreignkey field-ref="aId"/>

      </reference-descriptor>

so in case of  A<---->B  [1:1] i need a bidirectional navigation !!!!!
how to use ????


Do you mean how to map it?
Declare in both classes A and B a 1:1 reference-descriptor (both class tables need a FK column).

How to insert?
This depends strongly on the used auto-xxx settings. If auto-update/delete is enabled (and PK values handled by OJB) you can do e.g.:

broker.beginTransaction();
// first store both objects
broker.store(a, ObjectModification.INSERT);
// or let OJB detect the needed operation (more overhead)
//broker.store(a);
broker.store(b, ObjectModification.INSERT);
// now set references
a.setRelatedB(b);
b.setRelatedA(a);
// update both
broker.store(a, ObjectModification.UPDATE);
broker.commitTransaction();

or ()

// set references first
a.setRelatedB(b);
b.setRelatedA(a);
broker.beginTransaction();
// store both objects
broker.store(a);
// update b to force OJB to set the FK
// back to a (was 'null' after first store call)
broker.store(b);
broker.commitTransaction();

or if auto-update 'link' is used

broker.beginTransaction();
// first store both objects
broker.store(a, ObjectModification.INSERT);
broker.store(b, ObjectModification.INSERT);
// now set references
a.setRelatedB(b);
b.setRelatedA(a);
// update both
broker.store(a, ObjectModification.UPDATE);
broker.store(b, ObjectModification.UPDATE);
broker.commitTransaction();
...

regards,
Armin


my config :
  1. ojb 1.0.3
  2. i use the broker (PB-API)



Thanks a lot ....



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

Reply via email to