Write the POJO with lambok (original)

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Data  // Annotations to simplify writing code (ie constructors, setters)
@NoArgsConstructor
@AllArgsConstructor
@Entity // Annotation to simplify creating an entity, which is a lightweight persistence domain object. Typically, an entity represents a table in a relational database, and each entity instance corresponds to a row in that table.
public class Jokes {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;  // Unique identifier

    @Column(unique=true)
    private String joke;  // The Joke

    private int haha;  // Store joke likes
    private int boohoo;  // Store joke jeers
}
  • The @GeneratedValue annotation is to configure the way of increment of the specified column(field).
  • GenerationType.AUTO This GenerationType indicates that the persistence provider should automatically pick an appropriate strategy for the particular database. This is the default GenerationType, i.e. if we just use @GeneratedValue annotation then this value of GenerationType will be used.
  • The @Id annotation is one of the two mandatory annotations needed when creating an entity with JPA. The other one being @Entity. @Id does two things for us:
    • signifies that this field will be the unique identifier for this class when mapped to a database table
    • the presence of @Id lets the persistence layer know that all other fields within this class are to be mapped to database rows

Writing Setters and Getters (write POJO without lambok)

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Data  // Annotations to simplify writing code (ie constructors, setters)
@NoArgsConstructor
@AllArgsConstructor
@Entity // Annotation to simplify creating an entity, which is a lightweight persistence domain object. Typically, an entity represents a table in a relational database, and each entity instance corresponds to a row in that table.
public class Jokes {
    //@Id    @GeneratedValue(strategy = GenerationType.AUTO) private Long id;  // Unique identifier

    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    //@Column(unique=true) private String joke;  // The Joke

    private String joke;

    public String getJoke() {
        return joke;
    }

    public void setJoke(String id) {
        this.joke = joke;
    }


    // private int haha;  // Store joke likes

    private int haha;

    public int getHaha() {
        return haha;
    }

    public void setHaha(int id) {
        this.haha = haha;
    }

    //private int boohoo;  // Store joke jeers

    private int boohoo

     public int getHaha() {
        return haha;
    }

    public void setHaha(int id) {
        this.haha = haha;
    }
}