Thomas,

I made similar changes to support IDENTITY keys, but the "values" statement
was not supported (DB2 OS/390 7.1.1).

Instead, I used:

SELECT IDENTITY_VAL_LOCAL() FROM <tableName> FETCH FIRST ROW ONLY

The "FETCH FIRST ROW ONLY" clause is needed because, while the table is
really irrelevant, all rows are selected.  This is a performance issue for
large tables.  I suppose one could use an empty table instead.

This solution works in all flavors of DB2/UDB I've used so far.

-doug

-----Original Message-----
From: Thomas Olausson
To: [EMAIL PROTECTED]
Sent: 10/12/2002 2:48 AM
Subject: Re: [castor-dev] db2 identity columns and getting the value from it

Fixed it meself:

Since castor's open source, I added this to the
org.exolab.castor.jdo.drivers.IdentityKeyGenerator:

#  IdentityKeyGenerator
if ( !fName.equals("sybase") && !fName.equals("sql-server") &&
    !fName.equals("hsql") && !fName.equals("mysql") &&
    !fName.equals("informix") && !fName.equals("db2")) {
        throw new MappingException( Messages.format(
"mapping.keyGenNotCompatible",
        getClass().getName(), fName ) );

and this to
# generateKey():
else if ( _fName.equals("db2") ) {
    stmt = conn.prepareStatement(
    "values IDENTITY_VAL_LOCAL()");
    rs = stmt.executeQuery();
}

Seems to work.

When am I getting CVS commit permissions. ;)

/Thomas

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

**************************************************************************** 
This email may contain confidential material. 
If you were not an intended recipient, 
Please notify the sender and delete all copies. 
We may monitor email to and from our network. 
****************************************************************************

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to