users@glassfish.java.net

Re: JPA sequences making up weird numbers when migrating to GlassFish 2.1

From: <glassfish_at_javadesktop.org>
Date: Wed, 20 May 2009 14:55:03 PDT

In older version of TopLink Essentials both SEQUENCE and IDENTITY used to define IDENTITY on PostgreSQLPlatform.

It looks like your table defined using Identity (SERIAL). It uses sequence named tableName_IdName_seq to populate pk field.

Now TopLinkEssentials supports both SEQUENCE and IDENTITY, so GenerationType.SEQUENCE results in using default preallocation size (50).

TopLinkEssential thinks that it acquires values in chunks of 50; so the first value to use would be (newlyAcquiredValue - 49).

To fix instead of:
@SequenceGenerator(name = "STATS_SEQ_GEN", sequenceName = "stats_id_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "STATS_SEQ_GEN")

use:
@GeneratedValue(strategy = GenerationType.IDENTITY)

That will work with older TopLinkEssentials, too.
[Message sent by forum member 'ailitche' (ailitche)]

http://forums.java.net/jive/thread.jspa?messageID=347070