# Spring 5 course : Udemy - Unit 2
[toc]
## Unit 2: Building a Spring Boot Web App
*Quick overview of Spring in a very productive way.*
Generate html with dynamic content.
Disclaimer: how to use this but not going fully in details in this chapter.
- Spring Boot
- Spring MVC
- Spring Data JPA (Hibernate)
- H2 database
## Spring Initializr
Back in time you needed to create you own project with maven. Spring Initializr does this job for you (maven or gradle).
https://github.com/spring-projects/spring-boot/tree/main/spring-boot-project/spring-boot-starters
Create a simple webapp with: https://start.spring.io/
- Spring Web (Spring mvc)
- Spring Data JPA (abstraction for hibernate)
- H2 Database (our in memory database)
### Open the project in IntelliJ
For a maven project: ***From Existing source > Select the pom.xml*** file at the root of the project
Look at currated dependencies in the pom.xml by ctrl+click on the `parent.artifactId`
From the currated dependancies you can omit the version when you add them to your pom.xml because they are references in `spring-boot-parent-2.x.x.RELEASE.pom`
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
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***