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 15:16:00 PDT

Thank you!!!!! I spent the whole afternoon trying to figure this out, and now it works. The new version of TopLink Essentials breaks backwards compatability. I don't see mention of it in the GlassFish 2.1 release notes. I wonder why they did this? Now I have to build a new release of our app to move to GlassFish 2.1.


Thanks,
Ryan

> 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 'rdelaplante' (rdelaplante)]

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