Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Entities/Ids/SequenceGenerator"
< EclipseLink | UserGuide | JPA | Basic JPA Development
m (→@SequenceGenerator Annotation) |
m (→@SequenceGenerator Annotation) |
||
Line 3: | Line 3: | ||
* change the allocation size to match your application requirements or database performance parameters; | * change the allocation size to match your application requirements or database performance parameters; | ||
* 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 | * 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 | ||
− | + | {{EclipseLink_AttributeTable | |
− | + | |caption=@SequenceGenerator Attributes | |
− | + | |content= | |
− | + | <tr> | |
− | + | <td>'''<tt>name</tt>'''</td> | |
− | + | <td>The name of the generator must match the name of a <tt>GeneratedValue</tt> with its <tt>strategy</tt> attribute set to <tt>SEQUENCE</tt>.</td> | |
− | + | <td></td> | |
+ | <td>Yes</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>'''<tt>allocationSize</tt>'''</td> | ||
+ | <td>An <tt>int</tt> value that must match the increment size of the database sequence object.</td> | ||
+ | <td>50</td> | ||
+ | <td>No</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>'''<tt>initialValue</tt>'''</td> | ||
+ | <td>An <tt>int</tt> value to start all primary keys.</td> | ||
+ | <td>0</td> | ||
+ | <td>No</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>'''<tt>sequenceName</tt>'''</td> | ||
+ | <td>A <tt>String</tt> name of the sequence</td> | ||
+ | <td><tt>SequenceGenerator</tt></td> | ||
+ | <td>No</td> | ||
+ | </tr> | ||
+ | }} | ||
This example shows how to use this annotation to specify the allocation size for the <tt>SEQUENCE</tt> primary key generator named <tt>Cust_Seq</tt>. | This example shows how to use this annotation to specify the allocation size for the <tt>SEQUENCE</tt> primary key generator named <tt>Cust_Seq</tt>. |
Revision as of 14:12, 17 June 2010
@SequenceGenerator Annotation
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;
- 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
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 | SequenceGenerator | No |
This example shows how to use this annotation to specify the allocation size for the SEQUENCE primary key generator named Cust_Seq.
Usage of @SequenceGenerator
@Entity public class Employee implements Serializable { ... @Id @SequenceGenerator(name="Cust_Seq", allocationSize=25) @GeneratorValue(strategy=SEQUENCE, generator="Cust_Seq") @Column(name="CUST_ID") public Long getId() { return id; } ... }
For more information on the EclipseLink artifacts configured by these JPA metadata, refer to Descriptors and Sequencing.