Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package guru.springframework.spring5webapp.Bootstrap;

public class BootStrapData {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package guru.springframework.spring5webapp.domain;


import javax.persistence.*;

import java.util.Set;

@Entity
public class Author {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long id;

private String firstName;
private String lastName;
@ManyToMany
private Set<Books> books;

public Author() {
}

public String getFirstName() {
return firstName;
}

public Author(String firstName, String lastName, Set<Books> books) {
this.firstName = firstName;
this.lastName = lastName;
this.books = books;
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public Set<Books> getBooks() {
return books;
}

public void setBooks(Set<Books> books) {
this.books = books;
}

@Override
public String toString() {
return "Author{" +
"id=" + id +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", books=" + books +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Author author = (Author) o;

return id == author.id;
}

@Override
public int hashCode() {
return (int) (id ^ (id >>> 32));
}
}
86 changes: 86 additions & 0 deletions src/main/java/guru/springframework/spring5webapp/domain/Books.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package guru.springframework.spring5webapp.domain;

import javax.persistence.*;
import java.util.Set;

@Entity
public class Books {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String title;
private String isbn;

@ManyToMany
@JoinTable(name = "author_book", joinColumns = @JoinColumn(name = "books_id"),
inverseJoinColumns = @JoinColumn(name = "author_id"))
private Set<Author> authors;


public Books() {
}

public Books(String title, String isbn, Set<Author> authors) {
this.title = title;
this.isbn = isbn;
this.authors = authors;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Set<Author> getAuthors() {
return authors;
}

public void setAuthors(Set<Author> authors) {
this.authors = authors;
}

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;
}

@Override
public String toString() {
return "Books{" +
"id=" + id +
", title='" + title + '\'' +
", isbn='" + isbn + '\'' +
", authors=" + authors +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Books books = (Books) o;

return id != null ? id.equals(books.id) : books.id == null;
}

@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
}
7 changes: 7 additions & 0 deletions src/main/java/repositories/AuthorRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package repositories;

import guru.springframework.spring5webapp.domain.Author;
import org.springframework.data.repository.CrudRepository;

public interface AuthorRepository extends CrudRepository<Author, Long> {
}
7 changes: 7 additions & 0 deletions src/main/java/repositories/BookRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package repositories;

import guru.springframework.spring5webapp.domain.Books;
import org.springframework.data.repository.CrudRepository;

public interface BookRepository extends CrudRepository<Books, Long> {
}