diff --git a/src/main/java/guru/springframework/spring6webapp/domain/Author.java b/src/main/java/guru/springframework/spring6webapp/domain/Author.java new file mode 100644 index 00000000..7584ff81 --- /dev/null +++ b/src/main/java/guru/springframework/spring6webapp/domain/Author.java @@ -0,0 +1,50 @@ +package guru.springframework.spring6webapp.domain; + +import jakarta.persistence.*; + +import java.util.Set; + +public class Author { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + private String firstName; + + private String lastName; + + @ManyToMany + @JoinTable(name = "authors") + private Set books; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Set getBooks() { + return books; + } + + public void setBooks(Set books) { + this.books = books; + } +} diff --git a/src/main/java/guru/springframework/spring6webapp/domain/Book.java b/src/main/java/guru/springframework/spring6webapp/domain/Book.java new file mode 100644 index 00000000..fc94e609 --- /dev/null +++ b/src/main/java/guru/springframework/spring6webapp/domain/Book.java @@ -0,0 +1,53 @@ +package guru.springframework.spring6webapp.domain; + +import jakarta.persistence.*; + +import java.util.Set; + +@Entity +public class Book { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + private String title; + + private String isbn; + + @ManyToMany + @JoinTable(name = "author_book", joinColumns = @JoinColumn(name = "book_id"), + inverseJoinColumns = @JoinColumn(name = "author_id")) + private Set authors; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getIsbn() { + return isbn; + } + + public void setIsbn(String isbn) { + this.isbn = isbn; + } + + public Set getAuthors() { + return authors; + } + + public void setAuthors(Set authors) { + this.authors = authors; + } +}