|
| 1 | +package com.hellokoding.jpa; |
| 2 | + |
| 3 | +import com.hellokoding.jpa.model.Book; |
| 4 | +import com.hellokoding.jpa.model.BookPublisher; |
| 5 | +import com.hellokoding.jpa.model.Publisher; |
| 6 | +import com.hellokoding.jpa.repository.BookPublisherRepository; |
| 7 | +import com.hellokoding.jpa.repository.BookRepository; |
| 8 | +import com.hellokoding.jpa.repository.PublisherRepository; |
| 9 | +import lombok.RequiredArgsConstructor; |
| 10 | +import org.springframework.boot.CommandLineRunner; |
| 11 | +import org.springframework.boot.SpringApplication; |
| 12 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 13 | + |
| 14 | +import java.util.Arrays; |
| 15 | +import java.util.Date; |
| 16 | + |
| 17 | +@RequiredArgsConstructor |
| 18 | +@SpringBootApplication |
| 19 | +public class JpaApplication implements CommandLineRunner { |
| 20 | + private final BookRepository bookRepository; |
| 21 | + private final PublisherRepository publisherRepository; |
| 22 | + private final BookPublisherRepository bookPublisherRepository; |
| 23 | + |
| 24 | + public static void main(String[] args) { |
| 25 | + SpringApplication.run(JpaApplication.class, args); |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public void run(String... args) { |
| 30 | + Book b1 = new Book("Spring Boot"); |
| 31 | + Book b2 = new Book("Spring Data JPA"); |
| 32 | + bookRepository.saveAll(Arrays.asList(b1, b2)); |
| 33 | + |
| 34 | + Publisher p1 = new Publisher("HelloKoding 1"); |
| 35 | + Publisher p2 = new Publisher("HelloKoding 2"); |
| 36 | + publisherRepository.saveAll(Arrays.asList(p1, p2)); |
| 37 | + |
| 38 | + BookPublisher bp1 = new BookPublisher(b1, p1, new Date()); |
| 39 | + BookPublisher bp2 = new BookPublisher(b1, p2, new Date()); |
| 40 | + BookPublisher bp3 = new BookPublisher(b2, p1, new Date()); |
| 41 | + BookPublisher bp4 = new BookPublisher(b2, p2, new Date()); |
| 42 | + bookPublisherRepository.saveAll(Arrays.asList(bp1, bp2, bp3, bp4)); |
| 43 | + } |
| 44 | +} |
0 commit comments