I need to store domain object (DO) into DB.
The simplest approach is to add into DO definition some JPA annotations like @Entity
, @SequenceGenerator
, @Table
etc. but I don't want to mix DO with another conception like persisting. So I use separate DTO object and put annotations here.
As I'm a great Domain Driven Design follower I don't interconnect with DB directly and use Repository
pattern. If in the future I migrate from RDBMS to e.g. NoSQL all changes will be done only in Repository and my DO will be intact.
Thus the flow sequence is
DO -> Repository -converting-> DTO -> DB
As my DO has a lot of fields the conversion step is quite cumbersome and at the same time quite trivial: get fieldA from DO and put it into fieldA' in DTO (with simple transformations in some cases). Currently I do this manually in a separate Transformer
.
What are other (better?) approaches to do this conversion step?
UPDATE
Good comparison of bean mapping frameworks Dozer vs Orika vs Manual field mapping approach