Tutorialspoint examples

Learn java tutorial with examples for beginners online

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   
Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status