After reading some pages from DDD, I read about Repository pattern, then used it in an application successfully (I really liked it); then I noticed that EntityManager
is generic-repository-like
, but while I was reading about Repository I saw many examples on the web explaining how to impliment Repository pattern, and JPA was a simple Repository implementation between many implementations, like this website: http://www.lestard.eu/2015/generic_repository_part1/
The developer demonstrated in-memory implementations of Repository pattern, and in the second part : http://www.lestard.eu/2015/generic_repository_part2/, showed JPA implementation of repository pattern.
So here my question: while JPA is already like a generic repository, can we extend JPA to use in-memory, web services (e.g: REST CRUD) and entity persisting -- as JPA stands for Java PERSISITENCE API, (I wrote it in capital letters to show that it means a general persistence mechanism) -- as it seems that current JPA is tightly coupled with databases, but its name refer to a general use.
答案 0 :(得分:1)
Technically it's possible but I would prefer not to do this and don't have any links to specific implementation standard (like Java JPA). I prefer to hide all of implementation details inside my Repository
impl.
Moreover, I definitely don't like idea to put any persisting (like @Entity
) or conversion (like @XmlRootElement
from JAXB or @JsonProperty
) annotations inside my domain objects.
The reason is the simple: if in the future you will change Java JPA to smth new like Java New JPA you'll have to change you domain objects for this too. But it contradicts whole DDD idea.