Entity Object, DO, PO & POJO are synonyms. (in Spring Boot where they refer to the same thing)
● DO stands for Data Object or Domain Object (Domain is subject of your business logic like selling cars)
● PO stands for Persistence Object (Object that persists - it is saved, usually as Record in DB)
● POJO stands for Plain Old/Ordinary Java Object (just Properties, setters and getters)
Entity (something that exists: Tree, Dog, Table, Cloud)
● Class represents DB Table (inside your application)
● Object/Instance represents record in DB Table (inside your application)
● allows you to treat DB Record as an Object (inside your application)
Entity Class should only have (shouldn't contain any business logic or DB operations)
● Properties that are equivalent to Table Columns (can be of the same name or mapped through configuration)
● Optional helper Methods (setters, getters, equals, toString)
● Optional Constructor (for settings all the properties at once)
Command (DTO) as equivalent purpose as Entity (DO)
● Command (DTO) is used when beck-end wants to send/retrieve data to front-end
● Entity (DO) is used when beck-end wants to send/retrieve data to DB
PersonEntity.java
package com.ivoronline.test_spring_boot.model;
public class PersonEntity {
//PROPERTIES
private Long id;
private String name;
private Integer age;
//CONSTRUCTORS
public PersonEntity() { }
//SETTERS
public void setId (Long id) { this.id = id; }
public void setName(String name) { this.name = name; }
public void setAge (Integer age) { this.age = age; }
//GETTERS
public Long getId () { return id; }
public String getName() { return name; }
public Integer getAge () { return age; }
}