title: DDD, domain entities/VO and JPA
body: <p>I'm starting with DDD and you can image my brain is boiling.</p>
  
  <p>My question is related to my domain objects (entities, VO, ...) which represents my domain concepts/logic and how to persist/retrieve them.</p>
  
  <p>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.</p>
  
  <p>Then I see this Spring-data-jpa example <a href="http://spring.io/guides/gs/accessing-data-jpa/">http://spring.io/guides/gs/accessing-data-jpa/</a> and I become crazy.</p>
  
  <p>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 <code>customer</code>).</p>
  
  <p>Is the sample right? or Am I right?</p>
  
  <p>If I'm right and the domain and infrastructure must be separated, that means to store a customer I must have:</p>
  
  <ul>
  <li>a <code>Customer</code> class in my domain layer (that represents a customer and has all the logic operations)</li>
  <li>a <code>CustomerRepository</code> un my domain layer (that retrieves or stores customers from infrastructure layer)</li>
  <li>a <code>Customer</code> class in infrastructure layer, probably annotated with @Entity</li>
  <li>Some <code>CustomerReposityJPA</code> that know how to store/retrieve customers from database.</li>
  </ul>
  
  <p>Thanks for any clarification.</p>