File tree Expand file tree Collapse file tree 2 files changed +30
-8
lines changed
src/main/java/guru/springframework/spring6webapp/domain Expand file tree Collapse file tree 2 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 11package guru .springframework .spring6webapp .domain ;
22
3- import jakarta .persistence .Entity ;
4- import jakarta .persistence .GeneratedValue ;
5- import jakarta .persistence .GenerationType ;
6- import jakarta .persistence .Id ;
3+ import jakarta .persistence .*;
4+
5+ import java .util .Set ;
76
87/**
98 * Created by jt, Spring Framework Guru.
@@ -17,6 +16,17 @@ public class Author {
1716 private String firstName ;
1817 private String lastName ;
1918
19+ @ ManyToMany (mappedBy = "authors" )
20+ private Set <Book > books ;
21+
22+ public Set <Book > getBooks () {
23+ return books ;
24+ }
25+
26+ public void setBooks (Set <Book > books ) {
27+ this .books = books ;
28+ }
29+
2030 public Long getId () {
2131 return id ;
2232 }
Original file line number Diff line number Diff line change 11package guru .springframework .spring6webapp .domain ;
22
3- import jakarta .persistence .Entity ;
4- import jakarta .persistence .GeneratedValue ;
5- import jakarta .persistence .GenerationType ;
6- import jakarta .persistence .Id ;
3+ import jakarta .persistence .*;
4+
5+ import java .util .Set ;
76
87/**
98 * Created by jt, Spring Framework Guru.
@@ -17,6 +16,19 @@ public class Book {
1716 private String title ;
1817 private String isbn ;
1918
19+ @ ManyToMany
20+ @ JoinTable (name = "author_book" , joinColumns = @ JoinColumn (name = "book_id" ),
21+ inverseJoinColumns = @ JoinColumn (name = "author_id" ))
22+ private Set <Author > authors ;
23+
24+ public Set <Author > getAuthors () {
25+ return authors ;
26+ }
27+
28+ public void setAuthors (Set <Author > authors ) {
29+ this .authors = authors ;
30+ }
31+
2032 public Long getId () {
2133 return id ;
2234 }
You can’t perform that action at this time.
0 commit comments