DTOs, entities, and POJOs, oh my!
Before we start slinging code, we need to understand a fundamental paradigm: data transfer objects (DTOs) versus entities versus plain old Java objects (POJOs).
The differences between these three conventions aren’t something that is directly enforced by any sort of tool. That’s why it’s a paradigm and not a coding construct. So, what exactly are DTOs, entities, and POJOs?
- DTO: A class whose purpose is to transfer data, usually from server to client (or vice versa)
- Entity: A class whose purpose is to store/retrieve data to/from a data store
- POJO: A class that doesn’t extend any framework code nor has any sort of restrictions baked into it
Entities
When we write code to query data from a database, the class where our data ends up is commonly called an entity. This concept was turned into a standard when JPA was rolled out. Literally, every class involved with storing and retrieving data through...