openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vermeulen (JIRA)" <>
Subject [jira] Commented: (OPENJPA-1066) Generated ID starting with 0 can cause unexpected results
Date Mon, 21 Feb 2011 14:28:38 GMT


Vermeulen commented on OPENJPA-1066:

I was making a test case for another problem (which may or may not be related) and ran into
this with an in-memory hsqldb and generated schema.

Even if I use em.persist and even if I use a non-primitive id (I used Long), the entity with
id 0 is overwritten.
For most use cases OpenJPA doesn't force me to manually write SQL or manually create tables.
Yet for this simple use case I have to learn hsqldb's way of starting with 1 (which I only
use for small tests, we normally use mssql server).

> Generated ID starting with 0 can cause unexpected results
> ---------------------------------------------------------
>                 Key: OPENJPA-1066
>                 URL:
>             Project: OpenJPA
>          Issue Type: Improvement
>          Components: kernel
>    Affects Versions: 2.2.0
>         Environment: any DB that allows a generated id to start with 0.  And an entity
that maps that generated id to an int instead of an Integer
>            Reporter: B.J. Reed
>            Priority: Minor
>         Attachments: GeneratedIDStartsWith0.ZIP
> Several DB's allow a generated id column to start with 0.
> For instance, DB2 allows  "GENERATED ALWAYS AS IDENTITY (START WITH 0)...."
> When this is used, the very first object will have an id of 0.  When entities are first
created, the user usually won't fill in the corresponding id field (since it will be generated
by the DB when the entity is put in the DB), so it defaults to 0.  The entity manager then
uses this 0 and sees that an entity already exists and will update the old entity in stead
of creating a new one.
> This is not a large issue, because a user could simply specify "START WITH 1" as a very
simple workaround or they could use an Integer instead of an int, but it would be nice to
fix so that new users don't hit this problem.

This message is automatically generated by JIRA.
For more information on JIRA, see:


View raw message