CodesJava

Easy learning with example program codes

JPA SequenceGenerator annotation


The SequenceGenerator annotation defines a primary key generator that may be referenced by name when a generator element is specified for the GeneratedValue annotation. A sequence generator may be specified on the entity class or on the primary key field or property. The scope of the generator name is global to the persistence unit (across all generator types).

Example:

@Id
@SequenceGenerator(name="seqTest",sequenceName="TEST_SEQ")
@GeneratedValue(strategy=SEQUENCE,generator="seqTest")
private Integer studentId;

In first line we declared a SequenceGenerator with SeqTest name. It points to TEST_SEQ which is a database object. The SequenceGenerator name “SeqTest” will be used by @GeneratedValue annotation.

Attribute:

Name: A unique generator name that can be referenced by one or more classes to be the generator for primary key values. It is a required attribute.

Posted in JPA   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki