JPA Demo :book:

Using Spring Boot JPA to work with PostgreSQL

Tools and Skills:

Github Link


Since I had already worked extensively with Spring, I thought I might as well also learn JPA as it’s so common and powerful! Was interesting to see how easily Spring made working with the DB was, and how intuitive it was to interpret everything just as Java classes.

An example of one of the classes:

@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@Entity
public class Book extends BaseEntity {

  private String name;
  private String description;

  @ManyToMany
  @JoinTable(
      name = "authors_books",
      joinColumns = {
          @JoinColumn(name = "book_id")
      },
      inverseJoinColumns = {
          @JoinColumn(name = "author_id")
      }
  )
  private List<Author> authors;

  @OneToMany(mappedBy = "book")
  private List<Chapter> chapters;
}