Reputation: 1995
As per recommended practices documented for DDD or Hexagonal architecture - The domain Model should be separate from the data model representations that are more tied with actual technology used( table/column names, joins, etc, JPA annotation). A practical issue here is - how do you do things like optimistic version control in this model? Say you have a domain service that does read-->update-->save on a domain model. Now the JPA entity might have a version column that it can't pass upwards. Thus when the save call comes to the repo and the repo essentially once again does ( model --> entity) conversion and read+update, it will have no way to tell which version of the entity was read originally.
A secondary issue is the perf consideration of this involving a few extra reads here
Upvotes: 4
Views: 1589
Reputation: 732
You can do different things:
There's no silver bullet solution for a concrete usage of DDD into a project. It depends on your needs and desires.
Should I finish fast? Can I invest a bit of time in a persistence to domain transformation layer?
Is this code used/changed by someone later, that can do weird things if I don't put 'locks' on it?
Am I trying to create a pure DDD implementation?
Should I relax some rules to slowly introduce the DDD in my project, or to my team?
Interesting reading about JPA and Domain entities:
Upvotes: 5
Reputation: 1
There are different ways to do it. It mostly depends on where your application/layer lies in the architecture. Most time the application/layer that communicated with the entity model is at the foundation level. You are not obliged to create a separation when that serves no purpose. The proof of communication will be always the layer that will talk to this layer hence I do not see a need of creating one more transition. You could just pass the entity model/instance data.
Upvotes: 0