Easy learning with example program codes

JPA GeneratedValue annotation

The @GeneratedValue annotation provides the specification of generation strategies for the primary keys values.

@GeneratedValue(strategy=GenerationType.TABLE , generator="student_generator")


1. Strategy:
The strategy attribute is used to specify the primary key generation strategy that the persistence provider must use to generate the annotated entity primary key. It is an optional attribute. Strategy values are defined in javax.persistence.GeneratorType enumeration which are as follows:
1. AUTO: Based on the database’s support for primary key generation framework decides which generator type to be used.
2. IDENTITY: In this case database is responsible for determining and assigning the next primary key.
3. SEQUENCE: A sequence specify a database object that can be used as a source of primary key values. It uses @SequenceGenerator.
4. TABLE: It keeps a separate table with the primary key values. It uses @TableGenerator.
Note: Default value of Strategy attribute is AUTO.

2. Generator:
The Generator attribute is used to specify the name of the primary key generator to use as specified in the SequenceGenerator or TableGenerator annotation. It is an optional 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


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

Copyright © 2018 CodesJava Protection Status SiteMap Reference: Java Wiki