I'm starting with DDD and you can image my brain is boiling.
My question is related to my domain objects (entities, VO, ...) which represents my domain concepts/logic and how to persist/retrieve them.
The blue book says the repository is a way to represent collections on domain objects and is responsible to communicate with the infrastructure layer. I read also at some post the infrastructura layer is where you must use hibernate, JPA or whatever.
Then I see this Spring-data-jpa example http://spring.io/guides/gs/accessing-data-jpa/ and I become crazy.
The slogan say Spring-data-jpa is to create repositories easily and the previous samples seems to merge JPA annotations into a domain object (the customer
).
Is the sample right? or Am I right?
If I'm right and the domain and infrastructure must be separated, that means to store a customer I must have:
- a
Customer
class in my domain layer (that represents a customer and has all the logic operations) - a
CustomerRepository
un my domain layer (that retrieves or stores customers from infrastructure layer) - a
Customer
class in infrastructure layer, probably annotated with @Entity - Some
CustomerReposityJPA
that know how to store/retrieve customers from database.
Thanks for any clarification.