Jpa Cheat Sheet for annotations

Entity @Entity - marks class as the database entity @Entity public class Pokemon{} @Table - table name @Table(name = "Poke") public class Pokemon { } @Id - mark the primary key Annotate primary key @Id private int id; @GeneratedValue - the strategy for primary key GenerationType @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; GenerationType.IDENTITY The database is set AUTO_INCREMENT. Similar to SQL id NOT NULL AUTO_INCREMENT GenerationType.SQUENCE GenerationType.TABLE Use the TABLE in database to set the primary key for us, instead of the DBMS system....

January 15, 2023 · 16 min · Derry