From d4e4a8718e83b648c5b4164a1ded19f780b26b9b Mon Sep 17 00:00:00 2001 From: Arthur Dambrine Date: Sun, 30 Oct 2022 10:18:37 +0100 Subject: [PATCH] notes session 4 - JPA entities --- unit2_building_spring_boot_webapp.md | 91 +++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/unit2_building_spring_boot_webapp.md b/unit2_building_spring_boot_webapp.md index ad20469..8e1a175 100644 --- a/unit2_building_spring_boot_webapp.md +++ b/unit2_building_spring_boot_webapp.md @@ -46,7 +46,96 @@ From the currated dependancies you can omit the version when you add them to you Session 3 - 28/10/2022 - ended here
+## Github Workflow +[Starts from here](https://sparkers.udemy.com/course/spring-framework-5-beginner-to-guru/learn/lecture/17789252#overview) Github workflow. +- starting source +- end source -***Session 4 - 30/10/2022 : [Starts from here](https://sparkers.udemy.com/course/spring-framework-5-beginner-to-guru/learn/lecture/17789252#overview) Github workflow.*** \ No newline at end of file +1- fork the project and clone the repo to local + +2- co fork start with starting source + +3- use compare feature of git with relevant branch + + + +Compare to source (not fork) + +1st- >Copy the cloning url from original project + +``` +git remote add sfgRepo +git fetch sfgRepo +``` + +**Then in the GUI:** git > compare with branch. + + + +## JPA Entities + +*Java Persistance API - api for Hibernate.* + +Modeling the data. + +### Creating two POJOs + +**Book** + +- title +- isbn +- authors (`as Set`) + +**Author** + +- firstName +- lastName +- books (`as Set`) + +***NOTE: JPA requires a 0 args construcor*** + +Tips: Bring up the menu with `alt+insert` for constructors, getters and setters + + + +Now we are going to make them official JPA entities that can be persisted. + +***Leakage*** - object leaking up in an object database. + +### Assign JPA Id's + +```java +@Entity +public class Book { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + ... +``` + + + +### JPA Relationships + +*Many to many relationships.* (there will be a dedicated section in the framework course). + +``` +@ManyToMany(mappedBy = 'authors') +``` + +``` +@ManyToMany +@JoinTable(name= 'author_book', joinColumns = @JoinColumn(name= 'book_id'), inverseJoinColumns = @JoinColumn(name= 'author_id')) +``` + + + +Session 4 - 30/10/2022 : ended here + +
+ + + +***Session 5 - 31/10/2022 : [Starts from here](https://sparkers.udemy.com/course/spring-framework-5-beginner-to-guru/learn/lecture/17792132#notes) Equality in hibernate*** \ No newline at end of file