db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ron Gallagher" <rongallag...@bellsouth.net>
Subject RE: [BUG?] In order of FK description @ <reference-descriptor>
Date Wed, 17 Dec 2003 03:50:43 GMT
Antonio --

You are correct.  The order of inverse-foreignkey and foreignkey descriptors
is important.  Here's how I keep track of how they should be defined.



For collection-descriptors...

The first inverse-foreignkey descriptor establishes a link between the first
"PK field descriptor" on the 'current' class-descriptor with the
field-descriptor on the 'element-class-ref' class-descriptor whose 'name'
matches the value of the 'field-ref' attribute on the inverse-foreignkey
descriptor.  A "PK field-descriptor" is any field-descriptor that is
included in the primary key of the table (i.e. primary-key="true").
The second inverse-foreignkey descriptor does exactly the same thing, except
that it establishes a link with the second "PK field descriptor" on the
'current' class-descriptor.

For reference-descriptors...

The first foreignkey descriptor establishes a link between the
field-descriptor on the 'current' class-descriptor whose name matches the
'field-ref' attribute with the first "PK field descriptor" on the
'class-ref' class-descriptor.
The second foreignkey descriptor does the exactly the same thing, except
that it establishes a link with the second "PK field descriptor" on the
'class-ref' class-descriptor.

I hope this explanation helps.

Ron Gallagher
Atlanta, GA
rongallagher@bellsouth.net

-----Original Message-----
From: Antonio Gallardo [mailto:agallardo@agsoftware.dnsalias.com]
Sent: Monday, December 15, 2003 4:57 PM
To: ojb-dev@db.apache.org
Subject: [BUG?] In order of FK description @ <reference-descriptor>


Hi:

I found the follwing problem. I am not sure if this is a bug or lack of
documentation. Anyway, I think we need to see this:

I have a 2 fields Primary Key (PK) on a class A defined as follow:

<class-descriptor class="test.A" table="A">
  <field-descriptor name="id_1" primarykey="true" default-fetch="true"
      column="ID_A" jdbc-type="INTEGER"/>
  <field-descriptor name="id_2" primarykey="true" default-fetch="true"
      column="ID_B" jdbc-type="INTEGER"/>
  <collection-descriptor name="bList" element-class-ref="test.b"
          auto-update="false" auto-delete="false">
      <inverse-foreignkey field-ref="id_1"/>
      <inverse-foreignkey field-ref="id_2"/>
  </collection-descriptor>
</class-descriptor>

Please note the order how are defined the PK. First is id_1 then id_2! Now
the secodn class:

<class-descriptor class="test.B" table="B">
  <field-descriptor name="id" primarykey="true" default-fetch="true"
      column="ID_A" jdbc-type="INTEGER"/>
  <field-descriptor name="id_2" default-fetch="true"
      column="ID_B" jdbc-type="INTEGER"/>
  <field-descriptor name="id_1" default-fetch="true"
      column="ID_A" jdbc-type="INTEGER"/>
  <reference-descriptor name="A" class-ref="test.A"
          auto-update="false" auto-delete="false">
      <foreignkey field-ref="id_1"/>
      <foreignkey field-ref="id_2"/>
  </reference-descriptor>
</class-descriptor>

Seems like the order of the defined inverse-foreign keys is very important
(not documented at all website) since if in the sample we change the
"order" of id_1 and id_2 in both above describe <class-descriptor> just in
the <collection descriptor> of class A and the <reference-descriptor> of
class B We got an referential integrity error, reference from B not found
in A!

Note the order of fields in class B, (first id_2, follow id_1) they are
intentionally changed as they are in class A.

I hope the problem is good explained, if not please let me know. I will
try to explain it better.

Best Regards,

Antonio Gallardo


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message