You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Cl...@bit.admin.ch on 2005/06/27 08:30:22 UTC

Emitted SQL statement für primarykey-value 0?

Hi,

When I do an insert operation on a simple persistent class (Adress: int id,
String name, String firstname), then the following sql statements will be
emitted by ojb:

1119851348515|0|1|statement||SELECT ID FROM ADRESSE WHERE ID = '1' 
1119851348515|0|1|statement||INSERT INTO ADRESSE (ID,NAME,VORNAME) VALUES
('1','a1','b1') 
1119851348515|0|1|statement||SELECT ID FROM ADRESSE WHERE ID = '2' 
1119851348515|0|1|statement||INSERT INTO ADRESSE (ID,NAME,VORNAME) VALUES
('2','a2','b') 

But when the primarykey (int type) has the value 0, then only this will be
emitted, without a preceding select statement:

1119853301733|0|1|statement||INSERT INTO ADRESSE (ID,NAME,VORNAME) VALUES
('0','B0','M0') 

Why?
OJB 1.0.3, Broker-API, no autoincrement primarykey.

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


Re: Emitted SQL statement für primarykey-value 0?

Posted by Thomas Dudziak <to...@gmail.com>.
When you'e using the type int for your primary key (as opposed to
using Integer), then there isn't a language-provided 'null' value.
However OJB needs such a null value in order to determine whether the
object has already be stored (pk != null) or not. For the primitive
type int, the null value is therefore definied as 0.
I'd suggest you either don't use 0 for your pks or (better) change
your PK to Integer.

Tom

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