content: package com.bookstore.service;
  
  import com.bookstore.entity.Author;
  import com.bookstore.entity.Book;
  import com.bookstore.repository.AuthorRepository;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  @Service
  public class BookstoreService {
  
      private final AuthorRepository authorRepository;
  
      public BookstoreService(AuthorRepository authorRepository) {
          this.authorRepository = authorRepository;
      }
  
      public void persistAuthorWithBooks() {
  
          Author author = new Author()
                  .name("Joana Nimar")
                  .age(34)
                  .genre("History")
                  .addBook(new Book()
                          .title("A History of Ancient Prague")
                          .isbn("001-JN"))
                  .addBook(new Book()
                          .title("A People's History")
                          .isbn("002-JN"));
  
          authorRepository.save(author);
      }
  
      @Transactional(readOnly = true)
      public void displayAuthorWithBooks() {
  
          Author author = authorRepository.findByName("Joana Nimar");
  
          System.out.println(author + "  Books: " + author.getBooks());
      }
  }
  