Browse Source

notes session 4 - JPA entities

master
Arthur Dambrine 3 years ago
parent
commit
d4e4a8718e
  1. 91
      unit2_building_spring_boot_webapp.md

91
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 Session 3 - 28/10/2022 - ended here
<hr> <hr>
## 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.*** 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 <protocol:originalrepo/url>
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>`)
**Author**
- firstName
- lastName
- books (`as Set<Book>`)
***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
<hr>
***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***
Loading…
Cancel
Save