Skip to content

Instantly share code, notes, and snippets.

@coseos
Created October 31, 2022 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coseos/4a67dfa48ba3fcbef8cba62306b86fb5 to your computer and use it in GitHub Desktop.
Save coseos/4a67dfa48ba3fcbef8cba62306b86fb5 to your computer and use it in GitHub Desktop.

JPA @Identity Stragey values

Just to remember the strategies available in JPA for id generation. In most cases, AUTO will work fine as in

@Id
@GeneratedValue(strategy=GenerationType.AUTO)

Sometimes AUTO does not work. Use IDENTITY for a database that supports autoincement columns and SEQUENCE for a database that supports sequences. Few databases require TABLE

  1. AUTO: Automatically choose a strategy
  2. IDENTITY: Use autoincrement on identiy column
  3. SEQUENCE: Use sequence, see @SequenceGenerator.
  4. TABLE: Use table, see @TableGenerator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment