title: DTO objects for each entity
body: <p>I have inherited an application written in Java that uses JPA to access a database.  The application uses an design pattern that I haven't come across before and I would really appricate some guidance on why this pattern is used.  Like many applications, we have a front end, middleware, and back end database.  The database is accessed via DAOs.  Each method on the DAO loads a entity-DTO which is just a POJO with nothing but getters and setters and that entity-DTO is then passed into a entity-proper that has other methods that change the entity state.  An example [class names changed to protect the inocent]</p>
  
  <pre><code>enum Gender
  {
      Male,
      Female
  }
  
  class PersonDTO
  {
      private String mFirstName;
      private String mLastName;
      private Gender mGender;
      ...
  
      String getFirstName() { return this.mFirstName; }
      String setFirstName(String name) { this.mFirstName = name; }
      // etc
  }
  
  class Person
  {
      PersonDTO mDTO;
      Person(PersonDTO dto)
      {
          mDTO = dto;
      }
  
      String getFirstName() { return mDTO.getFirstName() }
      String setFirstName(String name) { mDTO.setFirstName(name); }
      // and so on
  
      void marry( Person aNotherPerson )
      {
          if( this.getGender()==Gender.Female &amp;&amp; 
                 aNotherPerson.getGender()==Gender.Male)
          {
              this.setLastName( aNotherPerson.getLastName() );
          }
          aNotherPerson.marry( this );
      }
  }
  </code></pre>
  
  <p>This is repeated across 30 or so entity classes, doubled to 60 with the DTOs, and I just cant get my head around why.  I understand (bits) about seperation of converns and I also understand (bits) about the difference between an EAO based design to say an active record based design.</p>
  
  <p>But does it really have to go this far?  Should there always be at least one "DB" object that contains nothing but getters and setters that map to the DB fields? </p>