users@glassfish.java.net

JPA sequences making up weird numbers when migrating to GlassFish 2.1

From: <glassfish_at_javadesktop.org>
Date: Wed, 20 May 2009 14:15:33 PDT

Hi,

I have an application that was developed and tested on GlassFish V2 UR2, PostgreSQL 8.3 and OpenSolaris 2008 11. I installed GlassFish 2.1 on the same computer then deployed the same application into it. The weirdest thing is happening. My application inserts records into the database then when it tries to commit there is an error:

Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "stats_pkey1"

I have the SQL logs set to FINE so I can see what it is doing:

select nextval('stats_id_seq')
INSERT INTO stats (id, total_desktop, total_mobilerich, optlock_version, total_mobilebasic, stats_date, total_tv, classification, unique_transactions, unique_desktop, trans_type, unique_mobilerich, hotel_code, unique_mobilebasic, total_transactions, unique_tv) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
        bind => [106, 1, 0, 1, 0, 2009-05-20, 0, SUCCESS, 1, 1, CHECK_IN, 0, TESTA, 0, 1, 0]

The insert statement used id 106 which is wrong. I have no idea where it got that number from. When I look in postgres I can see the current value of the stats_id_seq sequence is 158 and when I manually query "select nextval('stats_id_seq')" a bunch of times it gives me the correct values.

The JPA entity is annotated with:

@Id
@SequenceGenerator(name = "STATS_SEQ_GEN", sequenceName = "stats_id_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE,
                generator = "STATS_SEQ_GEN")
@Column(name = "id", nullable=false)
private Integer id;

I deployed a second application onto GlassFish 2.1 that uses a database and it suffers from the same problem. What is going on? I'm using the same JDBC driver, same datasource configuration, same .war files, etc.


Ryan
[Message sent by forum member 'rdelaplante' (rdelaplante)]

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