thanks for the fast reply
ok, I see
however i am not using primitives for my PKs and FKs and I use sequence managers for
PK generation.
Now, if i try to store an Object A that contains a reference to another EXISTING
Object B with PK = 0,
then OJB tries to store Object A and B, however since B has A PK = 0, it will try to
generate a new Identity
through the sequence manager and change my PK = 0 to some other value (storing a copy
of the Object), causing a FK constraint violation.
Creating a new Identity will cause at some time a call to
org.apache.ojb.broker.util.BrokerHelper.getAutoIncrementValue(...),
where this check is done (rc4 line 297): ( cv = current value)
if ((cv == null) || ((cv instanceof Number) && (((Number) cv).intValue() == 0))) {
-> then generate new autoincremented PK value
}
this causes my problem, the values here cannot be primitives (primitives are probably
wrapped somewhere in the code),
so i guess there is a problem when reading in non primitive data types, OJB should not
interpret a non primitive value of 0 as null reference
or said in another way, only when the target field is a primitive, a null value should
be wrapped to a primitive 0, else no change...
bye
danilo
> Hi,
>
> I believe it is possible *only* if you do not use a primitive to hold the
> primary key.
>
> In order to assign primary keys, OJB need to know if an object needs a key.
> If the key is stored as an Object e.g. Long, Integer, BigInteger etc then
> it checks to see if the attribute is null. If, however, they is a primitive
> e.g. int or long, the only way OJB can see if the object does not have a
> key is to check for a specific, arbitrary number. The number OJB currently
> looks for is zero.
>
> It *is* possible to have a nullable foreign key, but again *only* if the
> foreign key is not a primitive. Primitives *always* have a value, therefore
> the foregin key will always have a value.
>
> HTH,
>
> Cheers,
>
> Charles.
>
> >-----Original Message-----
>
> From: Danilo Tommasina [mailto:[EMAIL PROTECTED]
>
> >Sent: 04 August 2003 08:08
> >To: OJB Users List
> >Subject: Question on Primary Keys
> >
> >
> >Hi,
> >
> >since nobody answered my previous posts, i'll try to simplfy
> >my questions :)
> >Is it possibile with OJB (rc4) to use numeric primary key with
> >value = 0?
> >Is it possible to use a nullable foreign key (optional
> >reference) that references an other table's primary key with value = 0?
> >
> >If your answer is YES, then there is a bug, if your answer is
> >NO then i'd like to know why it should not be possible
> >and i'll have to run tons of SQL scripts for 'correcting' my
> >existing data :(
> >
> >thanks and bye
> >danilo
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
>
> This email and any attachments are strictly confidential and are intended
> solely for the addressee. If you are not the intended recipient you must
> not disclose, forward, copy or take any action in reliance on this message
> or its attachments. If you have received this email in error please notify
> the sender as soon as possible and delete it from your computer systems.
> Any views or opinions presented are solely those of the author and do not
> necessarily reflect those of HPD Software Limited or its affiliates.
>
> At present the integrity of email across the internet cannot be guaranteed
> and messages sent via this medium are potentially at risk. All liability
> is excluded to the extent permitted by law for any claims arising as a re-
> sult of the use of this medium to transmit information by or to
> HPD Software Limited or its affiliates.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
--
Danilo Tommasina, Dipl. Ing. FH Telecom
Software Engineer
RCS Riskmanagement Concepts Systems AG
Technoparkstrasse 1
CH-8005 Zuerich
T: +41 1 445 29 08
[EMAIL PROTECTED]
www.risksys.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]