@Identity
With @Identity we can specify additional attributes for database identity and sequences and we can additionally apply this on the class level (or on the @Id property).
It is useful to be able to specify @Identity
on the class level when using
@MappedBy
and the @Id property is inherited.
The additional properties we can specify include:
- start - start value
- cache - cache value (performance optimisation)
- generatedBy - By DEFAULT or ALWAYS
Example use
@Identity(generated = BY_DEFAULT, start = 1000, cache = 100)
@Entity
public class AuditLog {
...
start value
The start value is supported in DDL generation for H2, Postgres, Oracle and SQL Server sequences.
cache value
The cache value is an important performance optimisation available in some databases including Postgres, Oracle & NuoDB. This specifies how many identity values the database should generate and cache ahead of time and is useful for tables that have a lot of inserts.