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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M5</version>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
92 changes: 92 additions & 0 deletions src/main/java/guru/springframework/spring5webapp/model/Author.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package guru.springframework.spring5webapp.model;

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

/**
* Created by jt on 5/16/17.
*/
@Entity
public class Author {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;

@ManyToMany(mappedBy = "authors")
private Set<Book> books = new HashSet<>();

public Author() {
}

public Author(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

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

public Long getId() {
return id;
}

public void setId(Long 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<Book> getBooks() {
return books;
}

public void setBooks(Set<Book> books) {
this.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 != null ? id.equals(author.id) : author.id == null;
}

@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}

@Override
public String toString() {
return "Author{" +
"id=" + id +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", books=" + books +
'}';
}
}
105 changes: 105 additions & 0 deletions src/main/java/guru/springframework/spring5webapp/model/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package guru.springframework.spring5webapp.model;

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

/**
* Created by jt on 5/16/17.
*/
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String title;
private String isbn;
private String publisher;

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

public Book() {
}

public Book(String title, String isbn, String publisher) {
this.title = title;
this.isbn = isbn;
this.publisher = publisher;
}

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

public Long getId() {
return id;
}

public void setId(Long 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 String getPublisher() {
return publisher;
}

public void setPublisher(String publisher) {
this.publisher = publisher;
}

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

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

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

Book book = (Book) o;

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

@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}

@Override
public String toString() {
return "Book{" +
"id=" + id +
", title='" + title + '\'' +
", isbn='" + isbn + '\'' +
", publisher='" + publisher + '\'' +
", authors=" + authors +
'}';
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.h2.console.enabled=true