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

Spring Boot Controller Service Repository

Spring RESTful service Laur Spilca Youtube Tutorial series spring docs Spring Restful service is a popular backend application. The architecture usually is made up with 3 layers: Controller, Service, and Repository. Configuration setup @SpringBootApplication - define the app root The start point of program It’s with @ComponentScan - tell spring to create beans in which the classes have been annotated with. Spring RESTful Service architecture Spring RESTful service usually has this architecture....

January 1, 2023 · 7 min · Derry