Plain Old Java Objects (POJO)
A short reference for defining a Spring data object and JPA entity.
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;
}
@Entitymaps the class to a database table.@Idand@GeneratedValuedefine the primary key.@Datagenerates getters, setters,equals,hashCode, andtoString.
Choose fields and relationships that model your own system object, then continue with the repository and controller references in Java Spring Hacks.