content: package com.bookstore.entity;
  
  import javax.persistence.CascadeType;
  import javax.persistence.EmbeddedId;
  import javax.persistence.Entity;
  import javax.persistence.OneToMany;
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  @Entity
  public class Author implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @EmbeddedId
      private AuthorId id;
  
      private String genre;
  
      @OneToMany(cascade = CascadeType.ALL,
              mappedBy = "author", orphanRemoval = true)
      private List<Book> books = new ArrayList<>();
  
      public void addBook(Book book) {
          this.books.add(book);
          book.setAuthor(this);
      }
  
      public void removeBook(Book book) {
          book.setAuthor(null);
          this.books.remove(book);
      }
  
      public void removeBooks() {
          Iterator<Book> iterator = this.books.iterator();
  
          while (iterator.hasNext()) {
              Book book = iterator.next();
  
              book.setAuthor(null);
              iterator.remove();
          }
      }
  
      public AuthorId getId() {
          return id;
      }
  
      public void setId(AuthorId id) {
          this.id = id;
      }
  
      public String getGenre() {
          return genre;
      }
  
      public void setGenre(String genre) {
          this.genre = genre;
      }
  
      public List<Book> getBooks() {
          return books;
      }
  
      public void setBooks(List<Book> books) {
          this.books = books;
      }
  
      @Override
      public String toString() {
          return "Author{ " + "id=" + id + ", genre=" + genre + '}';
      }
  }