I have a table with an identity column:
When my castor objects insert data in there, I can't use the
key-generator="IDENTITY", I just get a weird error,
seems like it doesn't work with db2.
So, my solution was to use the identity column, and
key-generator="MAX", but that doesn't work either, because
the counter is internal in db2.
If someone else (non-castor) inserts data without the identity
specifically in the insert, db2 will autoincrement with the last value,
which probably collides with an existing id.
Also, if the identity in db2 is defined as "GENERATED ALWAYS", I get an
error
while inserting, because castor tries to set its own value and db2 doesn't
like that.
I know db2 has a IDENTITY_VAL_LOCAL(), which is very similar to
select @@identity in ms sql or last_identity_id mysql.
Test an insert on the table below and then do
values IDENTITY_VAL_LOCAL()
and you'll get the identity.
So, the final solution is to treat the identity just as and integer field
and have a trigger
update the id, if the value isn't set by castor [hate triggers].
Does anyone has a better solution?
Couldn't that be added to org.exolab.castor.jdo.drivers.IdentityKeyGenerator
?
CREATE TABLE test (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY ( START WITH 0 ,
INCREMENT BY 1 , NO CACHE))
/Thomas
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev