spring-boot Spring-Boot Microservice with JPA Book Model


package com.mcf7.spring.domain;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;

@lombok.EqualsAndHashCode(of = "isbn")
public class Book implements Serializable {

    public Book() {}

    @GeneratedValue(strategy= GenerationType.AUTO)
    private long id;

    @Size(min = 1)
    private String isbn;

    @Size(min = 1)
    private String title;

    @Size(min = 1)
    private String author;

    @Size(min = 1)
    private String description;

Just a note since a few things are going on here I wanted to break them down real quick.

All of the annotations with @lombok are generating some of our class's boiler plate

@lombok.Getter  //Creates getter methods for our variables

@lombok.Setter  //Creates setter methods four our variables

@lombok.EqualsAndHashCode(of = "isbn") //Creates Equals and Hashcode methods based off of the isbn variable

@lombok.ToString(exclude="id") //Creates a toString method based off of every variable except id

We also leveraged Validation in this Object

@NotNull  //This specifies that when validation is called this element shouldn't be null

@Size(min = 1)  //This specifies that when validation is called this String shouldn't be smaller than 1