Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search

EclipseLink/UserGuide/JPA/Basic JPA Development/Entities/Ids/SequenceGenerator

< EclipseLink‎ | UserGuide‎ | JPA‎ | Basic JPA Development
Revision as of 11:41, 21 November 2017 by Unnamed Poltroon (Talk) (Fixed annotation @GeneratedValue. Was @GeneratorValue)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

EclipseLink JPA

Mailing ListForumsIRCmattermost
OpenHelp WantedBug Day
Browse Source


If you use the @GeneratedValue annotation to specify a primary key generator of type SEQUENCE, then you can use the @SequenceGenerator annotation to fine-tune this primary key generator to do the following:

  • change the allocation size to match your application requirements or database performance parameters; (this should match your database sequence INCREMENT)
  • change the initial value to match an existing data model (for example, if you are building on an existing data set for which a range of
@SequenceGenerator Attributes
Attribute Description Default Required?
name The name of the generator must match the name of a GeneratedValue with its strategy attribute set to SEQUENCE. Yes
allocationSize An int value that must match the increment size of the database sequence object. 50 No
initialValue An int value to start all primary keys. 0 No
sequenceName A String name of the sequence No

The following example shows how to use this annotation to specify the allocation size for the SEQUENCE primary key generator named Emp_Seq.

Example: @SequenceGenerator
 public class Employee implements Serializable {
     @SequenceGenerator(name="Emp_Seq", allocationSize=25)
     @GeneratedValue(strategy=SEQUENCE, generator="Emp_Seq")
     public Long getId() {
         return id;
Example: Using <sequence-generator>
<entity class="Employee">
        <id name="id">
            <column name="EMP_ID"/>
            <generated-value generator="Emp_Seq" strategy="SEQUENCE"/>
            <sequence-generator name="Emp_Seq" allocationSize="25"/>

Version: 2.2.0 DRAFT
Other versions...

Back to the top