java - DDD, domain entities/VO and JPA -


i'm starting ddd , can image brain boiling.

my question related domain objects (entities, vo, ...) represents domain concepts/logic , how persist/retrieve them.

the blue book says repository way represent collections on domain objects , responsible communicate infrastructure layer. read @ post infrastructura layer must use hibernate, jpa or whatever.

then see spring-data-jpa example http://spring.io/guides/gs/accessing-data-jpa/ , become crazy.

the slogan spring-data-jpa create repositories , previous samples seems merge jpa annotations domain object (the customer).

is sample right? or right?

if i'm right , domain , infrastructure must separated, means store customer must have:

  • a customer class in domain layer (that represents customer , has logic operations)
  • a customerrepository un domain layer (that retrieves or stores customers infrastructure layer)
  • a customer class in infrastructure layer, annotated @entity
  • some customerreposityjpa know how store/retrieve customers database.

thanks clarification.

in ddd, repository object participates in domain abstracts away backing store.

if annotate domain objects jpa annotations, persistence mechanism has bled domain. have tied domain structure persistence structure not ideal.

your jpacustomerrepository (implements icustomerrepository) map unannotated domain classes (customer) annotated jpa representation - jpa customer. keeps annotations out of domain classes, cleaner. allows vary jpa persistence structure independently of domain structure. cost benefit complexity of mapping code.

interface icustomerrepository {}  class jpacustomerrepository implements icustomerrepository {      void save(customer customer) {           jpacustomer jpacustomer = map(customer);           save(jpacustomer);      } }  class customer {}  class jpacustomer {} 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -