Try adding a version column to your Entity, or stop using primitives for your id columns. OpenJPA does not know the difference between an id that has a value of zero, and one that is uninitialized.
-Rick On Mon, May 4, 2009 at 2:26 PM, B.J. Reed <[email protected]> wrote: > I have a testcase where a DB2 DB is already created. It has 2 tables and > the web user preferences table has an identity column that is defined as > "generated always as identity (start with 0, ..." > > In the test case, I am expecting 2 sets of 2 inserts each into this table. > The first 2 objects should have id's of 0 and 1 (works fine) and the 2nd > set should have id's of 2 and 3 - what happens is that the web user > preference entities have never had their id set so both of their ids are > defaulted to 0. In stead of inserting rows, the entity manager sees the id > of 0 on both 2nd set objects and then does an update in the DB on the very > first record (since that one's id correctly is 0). > > Should OpenJPA be able to handle a generated column that starts with 0 (I > can create a JIRA for an enhancement) or is it common knowledge that the DB > should start with a non zero number or is there something that I should set > the id to in the new web user preferece entities so that they will always be > inserted? > > By changing the DDL to start with 1 in stead of 0, this problem is avoided > and 4 rows are inserted into the DB properly with id's 1 - 4. > > --B.J. Reed >
