title: GWT + entities + JPA + DTO + Dozer
body: <p>I am wondering what is the best way to handle mapping of entity beans (JPA 2) to DTOs.
  Since you cannot use entity beans "directly" with GWT, you need to handle DTOs instead.</p>
  
  <p>I have several entities with various relationships (OneToOne, OneToMany, ManyToMany with a join table etc).
  Initially i started converting all entities to DTOs by hand with the help of a class MyEntityTransform.java with methods like :</p>
  
  <pre><code>  static final public CarBean persistant2Bean(CarPersist) {
              return new CarBean(cartPersist.getId(), carPersist.getName(),
                      carPersist.getDescription());
          }
  </code></pre>
  
  <p>Other methods are : persistent2BeanCollection(...),  persistent2BeanMap(...),  bean2Persistent(...),  bean2PersistentCollection(...)</p>
  
  <p>That becomes a fastidious task when handling collections, especially when the same entity has references to several other entities;</p>
  
  <p>I have been thinking about using the DOZER framework to handle the mapping between entities and DTOs.
  It is mentionned here : <a href="http://code.google.com/intl/fr/webtoolkit/articles/using_gwt_with_hibernate.html" rel="nofollow">http://code.google.com/intl/fr/webtoolkit/articles/using_gwt_with_hibernate.html</a></p>
  
  <p>However i am not sure how well it handles the various JPA mappings (manytomany for instance) and how much work it is to configure it in the dozer-bean-mappings.xml file.
  Also i guess this framework is intensively using reflection to perform mapping operations. Such approach is much slower than mapping performed "by hands", e.g. when i use the methods in my MyEntityTransform.java class.</p>
  
  <p>What do you suggest ? i'm interested in everybody's experience handling  JPA entities with GWT.</p>
  
  <p>Thanks.</p>
  
  <p>Celinio</p>
  
  <p><a href="http://www.celinio.net/techblog" rel="nofollow">http://www.celinio.net/techblog</a></p>