From 1c79e3a2983a811991338e87121cce5bad5581dc Mon Sep 17 00:00:00 2001 From: John Thompson Date: Tue, 16 May 2017 15:13:58 -0400 Subject: [PATCH 1/6] adding JPA example --- .../spring5webapp/model/Author.java | 67 ++++++++++++++++ .../spring5webapp/model/Book.java | 79 +++++++++++++++++++ src/main/resources/application.properties | 1 + 3 files changed, 147 insertions(+) create mode 100644 src/main/java/guru/springframework/spring5webapp/model/Author.java create mode 100644 src/main/java/guru/springframework/spring5webapp/model/Book.java diff --git a/src/main/java/guru/springframework/spring5webapp/model/Author.java b/src/main/java/guru/springframework/spring5webapp/model/Author.java new file mode 100644 index 0000000000..ff7d926325 --- /dev/null +++ b/src/main/java/guru/springframework/spring5webapp/model/Author.java @@ -0,0 +1,67 @@ +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 books = new HashSet<>(); + + public Author() { + } + + public Author(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public Author(String firstName, String lastName, Set 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 getBooks() { + return books; + } + + public void setBooks(Set books) { + this.books = books; + } +} diff --git a/src/main/java/guru/springframework/spring5webapp/model/Book.java b/src/main/java/guru/springframework/spring5webapp/model/Book.java new file mode 100644 index 0000000000..eb04853b53 --- /dev/null +++ b/src/main/java/guru/springframework/spring5webapp/model/Book.java @@ -0,0 +1,79 @@ +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 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 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 getAuthors() { + return authors; + } + + public void setAuthors(Set authors) { + this.authors = authors; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e69de29bb2..69b89983cb 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.h2.console.enabled=true \ No newline at end of file From 405e6a6a22d82a1589b4828a9901cb9d6f66935f Mon Sep 17 00:00:00 2001 From: John Thompson Date: Mon, 19 Jun 2017 13:55:31 -0400 Subject: [PATCH 2/6] Updating Spring Boot Version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index deb18b1374..a9350676b0 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.0.BUILD-SNAPSHOT + 2.0.0.M2 From ee5272e39285327876d7bd04d96a0ff2573cf9d8 Mon Sep 17 00:00:00 2001 From: John Thompson Date: Mon, 31 Jul 2017 16:44:32 -0400 Subject: [PATCH 3/6] Updating Spring Boot Version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a9350676b0..db64bfd00c 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.0.M2 + 2.0.0.M3 From da29234779a0c3bb5313bb5c98470274c0f2891b Mon Sep 17 00:00:00 2001 From: springframeworkguru Date: Sat, 9 Dec 2017 22:33:40 +0530 Subject: [PATCH 4/6] Updated to 2.0.0.M7 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4495165e07..209f115ce4 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.0.M5 + 2.0.0.M7 From fcb2d9f9f63189e9d358ce256f72245e1fe69a6f Mon Sep 17 00:00:00 2001 From: springframeworkguru Date: Sat, 17 Mar 2018 18:39:26 +0530 Subject: [PATCH 5/6] Updated to Spring Boot 2.0.0.RELEASE --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 209f115ce4..c1260dc5bd 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.0.M7 + 2.0.0.RELEASE From 46a9a0ee05eaa8dfd043d4429599ab6fdb48bfd5 Mon Sep 17 00:00:00 2001 From: springframeworkguru Date: Tue, 4 Dec 2018 00:01:51 +0530 Subject: [PATCH 6/6] Upgraded to Spring Boot 2.1.0.RELEASE --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c1260dc5bd..eb12eaf80d 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.0.RELEASE + 2.1.0.RELEASE