
Entity vs DTO vs Model — Stop Using These Terms Interchangeably
Do you ever confuse yourself with the terms Entity, Model, and DTO? Sometimes you might hear your lecturer say that you can call an Entity a Model, but is that really true? They may sound similar, but they are actually quite different. Let's understand what they really are and what they actually do. Entity An Entity represents a database table using annotations like @entity . Think of it as a real table in your database. Example: Student Table @Entity @Table ( name = "students" ) public class StudentEntity { @Id @GeneratedValue ( strategy = GenerationType . IDENTITY ) private Long id ; private String name ; private String email ; private String password ; } An Entity is used by JPA/Hibernate. It is tightly coupled to the database and typically contains all fields, including sensitive ones such as passwords. DTO (Data Transfer Object) A DTO is used to transfer data between layers. It is not directly connected to the database. It is a safer, filtered version of your data that you send to
Continue reading on Dev.to Webdev
Opens in a new tab


