Hi,

[EMAIL PROTECTED] wrote:
Hi,

I' ve got a simple object with mandant, id as primary key. As such I can insert it 
into the database.
If I now define a relation to another object using a foreign key my insert fails with 
primary key missing.
This is due to the fact that the Relation Object is null, i.e. the relation is not 
defined for this object.

I do not understand why ojb "overwrites" my primary key (mandant) from the missing relation ? I am using ojb rc5 and SAPDB.


Try latest from CVS (is stable). Fields defined as PK and part of a FK will never be set to 'null' when the reference is removed (reference is null).
Please read the updated documentation about 1:1 reference and "Linking"
http://db.apache.org/ojb/tutorial3.html#1:1%20auto-xxx%20setting


In rc5:
If you only set the FK but not the referenced object itself, OJB assume the reference is removed and set all FK to null (this is not expected when auto-update false is set, that's the reason why we improve the auto-xxx settings in rc6).
Try to set the FK, then call PB.retrieveAllReferences(...) (or PB.retrieveReference) to retrieve the referenced object and then update Address.


regards,
Armin

Thanks for any ideas,

Stefan

E.g.

create table Adresse(
  mandant VARCHAR(3) not null,
  id FIXED(32) not null,
   plz VARCHAR(200),
 fk_person FIXED(32),
 primary key (mandant, id)
);
create table Person(
  mandant VARCHAR(3) not null,
  id FIXED(32) not null,
   name VARCHAR(200),
 primary key (mandant, id)
);

<class-descriptor    class="test.AdresseValue" table="Adresse">
    <field-descriptor  name="mandant" column="mandant" jdbc-type="VARCHAR" 
primarykey="true"/>
    <field-descriptor  name="id" column="ID" jdbc-type="BIGINT" primarykey="true"/>
    <field-descriptor  name="plz" column="plz" jdbc-type="VARCHAR"/>

<field-descriptor name="fk_person" column="fk_person" jdbc-type="BIGINT" />

       <reference-descriptor  name="personObj"  class-ref="test.PersonValue"
            auto-retrieve="false" auto-update="false" auto-delete="false">
        <foreignkey field-ref="mandant"/>
        <foreignkey field-ref="fk_person"/>
    </reference-descriptor>
   </class-descriptor>

The sql generated looks like this:
INSERT INTO Adresse (mandant,ID,plz,fk_person) VALUES ('','1','761','0')




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




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



Reply via email to