Plain Old Java Objects (POJO)

1 min read

POJO and Entity

Your data object begins as a Java class. Adding JPA annotations makes it persistable; Lombok removes routine accessor, mutator, and constructor code.

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class Data {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;
}
  • @Entity maps the class to a database table.
  • @Id and @GeneratedValue define the primary key.
  • @Data generates getters, setters, equals, hashCode, and toString.

Choose fields and relationships that model your own system object, then continue with the repository and controller references in Java Spring Hacks.

Course Timeline