Skip to main content
1 of 5
Daniel Kaplan
  • 6.8k
  • 5
  • 33
  • 47

In domain driven design, can there be a one-to-one mapping between a database table and a Value Object?

Lets suppose there's a database schema defined like this:

Person.mail_address_key ----- Address.address_key
Person.billing_address_key ----- Address.address_key

A Person has a mailing address and a billing address. As a denormalization technique, we create a separate Address table. Most of the time the mail_address_key and the billing_address_key of a single Person will be the same value (ie: their mailing and billing address key will be the same).

In my database the Address has an identity (the address key). But, in my domain model, I don't see a compelling reason for the Address to be an Entity, I'd like it to be a Value Object.

In DDD, is this an option?

  1. If so, where/when/how does the address lose its database identity so it can be used as a Value Object in the Domain Layer? Or, am I supposed to keep the database identity in the Value Object?
  2. When the model needs to be persisted in the database, how does it get its identity back? Am I supposed to go through a process of a) Find an address by these fields, b) if it doesn't exist, create a new one c) if it does, update the fields?
Daniel Kaplan
  • 6.8k
  • 5
  • 33
  • 47