How are Value Objects stored in the database?

It’s ok to store Value Objects in a separate table, for the very reasons you’ve described. However, I think you’re misunderstanding Entities vs VOs – it’s not a persistence related concern.

Here’s an example:

Assume that a Company and Person both have the same mail Address. Which of these statements do consider valid?

  1. “If I modify Company.Address, I want
    Person.Address to automatically get
    those changes”
  2. “If I modify Company.Address, it
    must not affect Person.Address”

If 1 is true, Address should be an Entity, and therefore has it’s own table

If 2 is true, Address should be a Value Object. It could be stored as a component within the parent Entity’s table, or it could have it’s own table (better database normalisation).

As you can see, how Address is persisted has nothing to do with Entity/VO semantics.

Leave a Comment