Should JPA entities and DDD entities be the same classes?

后端 未结 3 1029
忘了有多久
忘了有多久 2020-12-31 13:30

There are classes that are entities according to DDD, and there are classes that have @javax.persistence.Entity annotation. Should they be the same classes? Or

3条回答
  •  生来不讨喜
    2020-12-31 14:33

    After some more experience with JPA and microservices, I would say that I would most likely not separate them when using JPA, unless there's a reason that makes me do otherwise. On the other hand, entities in a single bounded context do not necessarily have to be only JPA entities. It's possible to have both entities mapped by JPA implementation and entities mapped from DTOs using other technologies (like JSON mappers) or manually.

提交回复
热议问题