Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 262889 - JPA @SequenceGenerator not working for DB2 native sequences
Summary: JPA @SequenceGenerator not working for DB2 native sequences
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: submitted_patch
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-29 06:08 EST by Jean-David Maillefer CLA
Modified: 2022-06-09 10:27 EDT (History)
2 users (show)

See Also:


Attachments
Patch of the changes I made (6.49 KB, patch)
2009-01-29 06:08 EST, Jean-David Maillefer CLA
peter.krogh: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-David Maillefer CLA 2009-01-29 06:08:52 EST
Created attachment 124135 [details]
Patch of the changes I made

The @SequenceGenerator doesn't do what's expected for DB2:
DB2 supports both identity columns and native sequences. But the current implementation doesn't make the difference.

For example, the following code should work:
@Entity
@SequenceGenerator(initialValue=1,sequenceName="ENTREPRISE_SEQ",name="Entreprise_seq",allocationSize=1)
public class Entreprise implements Serializable {
  @Id
  @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="Entreprise_seq")
  private Integer id;
  ...
}

But the current implementation ignores the sequence and assumes an identity column (as explained in the doc/wiki, the sequences are currently not fully implemented for DB other than Oracle). This causes problems of having the id field set to null (expecting the DB will auto-affect the IDENTITY column) instead of already set by the next value of the sequence.

I made a patch which works for us and suggest to include it in the next version.
(This small patch includes some coherency changes in comments + serialVersionUID, but you can ignore them if you want)

I point out that the SQL used in sequence generation I propose is ISO SQL 2003 compliant and could be used on other platform following this standard.
I didn't found in the current API the way to specify finer grained properties of sequences other than "increment by". According to ISO SQL 2003, the following additional options should be available: data type, start with, maxvalue, minvalue and cycle.
Comment 1 Tom Ware CLA 2009-02-04 12:59:17 EST
Setting target to 1.1X so this bug will be a candidate for the first patch release after 1.1
Comment 2 James Sutherland CLA 2009-10-26 15:16:59 EDT
Fixed in main (2.0 stream).
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:17:06 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:27:42 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink