Tuesday, March 26, 2013

Obtaining Primary Key while using JDBCHelper

If you plan to insert a new record into a WCS OOB or Custom table using JDBCHelper, you should ensure that there is no conflict between the EJBs and your program.

The KEYS.PREFETCHSIZE field reserves  a block of primary key values for use between the EJBs, so if you try doing an insert by doing SELECT MAX+1 then , it would result in Duplicate Key exception.

To avoid this, use the KeysManager to get the next primary key for using in JDBCHelper.

long
primaryKeyId= com.ibm.commerce.key.ECKeyManager.singleton().getNextKeyAsLong("table_name");
This would ensure you do not pick up a Key which is already being used by the EJBs.







Labels: , ,

0 Comments:

Post a Comment

<< Home