Java Omnibus
OOAD & Architecture / Reference & Downloads / DTO vs Entity vs Value Object
Reference DTO Entity Value Object Java
Reference & Downloads

Many modeling bugs begin when teams let transport objects, identity-bearing objects, and conceptual values blur into one shapeless model.

DTOs, entities, and value objects often look similar at first glance because they all hold data. Their design role is different. DTOs move data between boundaries. Entities carry identity and lifecycle. Value objects represent concepts defined by their attributes rather than by identity.

Why This Topic Matters

Why it matters in real Java systems

If an order request DTO starts acquiring domain behavior, or if a shipping address becomes a mutable entity without identity reason, the codebase loses modeling clarity fast. Keeping these object roles distinct improves architecture and makes refactoring safer.

Core Explanation

The main reference idea

DTOs are usually boundary-facing and shaped for serialization, requests, responses, or integration. Entities live in the domain or persistence model and carry identity across time. Value objects represent concepts such as money, address, or quantity and are usually best kept immutable. The more complex the domain becomes, the more valuable these distinctions are.

Concept Breakdown

Key ideas to keep in mind

Reference

DTO

Boundary-shaped data carrier with no obligation to own domain behavior.

Reference

Entity

Identity-bearing object whose lifecycle matters across time.

Reference

Value Object

Concept object defined by attributes and usually safest as immutable.

Comparison table

Comparison table

Type What defines it Typical role
DTOBoundary and transport needsRequests, responses, external integration
EntityIdentity and lifecycleDomain core objects such as Order or Customer
Value ObjectMeaningful attributesMoney, Address, Quantity, TaxRate
Java Example

Java example in the Order Management domain

Java example: each object role in one workflow
package org.javaomnibus.reference;

public record PlaceOrderRequest(String customerId, List<String> productIds) {}

public final class Order {
    private final OrderId id;
    private final List<OrderLine> lines;

    public Order(OrderId id, List<OrderLine> lines) {
        this.id = id;
        this.lines = lines;
    }
}

public record Money(BigDecimal amount, Currency currency) {}
Code Walkthrough

Step by step

  1. The request DTO is shaped for the boundary.
  2. The entity carries identity and domain lifecycle.
  3. The value object represents a conceptual quantity without identity.
  4. Keeping those roles clear prevents a lot of accidental model confusion later.
Real-World Usage

Where this helps in practice

  • Boundary design and domain modeling reviews
  • Refactoring service layers with mixed object roles
  • Teaching DDD-adjacent modeling discipline
Trade-Offs

Trade-offs and when to be careful

  • Clear separation improves model integrity, but tiny applications can sometimes tolerate simpler shapes temporarily.
  • The danger is not smallness. It is letting those temporary shortcuts become permanent ambiguity.
Common Mistakes

Frequent mistakes to watch for

  • Putting domain behavior on request or response DTOs
  • Making value objects mutable without strong reason
  • Using entities for every concept just because persistence exists
  • Ignoring identity semantics when designing core domain types
Related Pages

Related concepts


What To Read Next