jpadomain-object

Are domain objects the same as JPA entities?


Are domain objects the same as JPA entities? If I have a value object (e.g. a dollar bill), how can I (or even should I) store that in the datastore as a reference object?

What are the subtleties of domain objects being entities in some cases and value objects in other cases? Could anyone direct me to a good paper on this?


Solution

  • "Domain object" is a more conceptual term; "JPA entity" refers to a specific technology useful for implementing domain objects.

    Generally domain objects correspond to the nouns (orders, invoices, customers, etc.) in your domain. Usually we see these as being closer to the database rather than pure data transfer objects. So you might see ORM annotations on the classes you use to implement your domain objects, for example.

    A lot of people implement domain objects in an anemic way--mostly properties with ORM mappings, but no real logic on the domain objects themselves. They put the logic in domain services.

    On the other hand proponents of domain-driven design put the logic on the domain objects.

    Either way these are the domain objects in your system.

    JPA entities are classes that you annotate with @Entity, @Column, @ManyToOne, etc. This is a way to implement domain objects. You may decide to put domain logic on the objects themselves, as noted above.