title: what is a good pattern for converting between hibernate entities and data transfer objects?
body: <p>I have had similar questions and concerns as to how to convert between Hibernate entities and data transfer objects to be returned by a web service as are discussed in this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/1086204/is-using-data-transfer-objects-in-ejb3-considered-best-practice">Is using data transfer objects in ejb3 considered best practice</a></p>
  
  <p>One of the factors mentioned here is that if the domain model changes, a set of DTOs will protect consumers in the case of a web service.</p>
  
  <p>Even though it seems like it will add a substantial amount of code to my project, this reasoning seems sound.</p>
  
  <p>Is there a good design pattern that I can use to convert a Hibernate entity (which implements an interface) to a DTO that implements the same interface?</p>
  
  <p>So assuming both of the following implement 'Book', I would need to convert a BookEntity.class to a BookDTO.class so that I can let JAXB serialize and return.</p>
  
  <p>Again, this whole prospect seems dubious to me, but if there are good patterns out there for helping to deal with this conversion, I would love to get some insight.</p>
  
  <p>Is there perhaps some interesting way to convert via reflection?  Or a 'builder' pattern that I'm not thinking of?</p>
  
  <p>Should I just ignore the DTO pattern and pass entities around?</p>