JPA GeneratedValue annotation

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

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

Attributes:

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.

Please follow and like us:
Content Protection by DMCA.com