title: How to prevent eclipse-link from fetching lazy loaded attributes during DTO mapping?
body: <p>I've a bit paradox question, but I'll try to explain it as meaningful as possible.</p>
  
  <p><strong>Background</strong></p>
  
  <p>I have a 3-tiered application setup involving Glassfish 3.1.2.2, JPA 2.0 (eclipse-link 2.3.3), MySQL database and a stand-alone Swing-Client. I access the EJB's with JNDI by remote interfaces. Moreover I use static weaving in order to benefit from lazy loading complex relations. On the stand-alone Swing client, I use load groups to selectively fetch only the relations I really need.</p>
  
  <p><strong>Goal</strong></p>
  
  <p>For the purpose of reducing network traffic, I plan to transform the queried @Entity annotated database objects to DTO's (Data Transfer Objects, POJO's) by using this <a href="http://modelmapper.org/" rel="nofollow noreferrer">model mapper</a>.</p>
  
  <p><strong>The Big Issue</strong></p>
  
  <p>During the mapping of the @Entity-Objects to the corresponding DTO's, the accessors of each field on the @Entity is accessed which in turn does catch up all the non-fetched (lazy loaded indirect lists) fields from the database, resulting in big objects again.</p>
  
  <p>My goal is to map the lazy-fetched @Entitiy annotated objects as they are, without fetching  the intentionally non-fetched relations, in order to keep the objects as small as possible before they are being serialized and transfered to the remote client.</p>
  
  <p>Any ideas ?</p>
  
  <p>EDIT: I found <a href="https://stackoverflow.com/questions/5552379/prevent-dozer-from-triggering-hibernate-lazy-loading">this thread</a> from someone using <a href="http://dozer.sourceforge.net/documentation/about.html" rel="nofollow noreferrer">Dozer</a>, I'm looking for something similar for <a href="http://modelmapper.org/" rel="nofollow noreferrer">ModelMapper</a>.</p>
  
  <p><strong>What I tried so far (without success):</strong></p>
  
  <ul>
  <li>I detached the query result from the entity manager before mapping
  (still lazy fetching) </li>
  <li>clearing and closing the entity manager after querying and
  before DTO-mapping (still lazy fetching)</li>
  <li>declaring the queried
  List final (so that the lazy loading mechanism cannot</li>
  </ul>
  
  <p>override attributes that are fetched afterwards, but it did)</p>
  
  <p><strong>Many thanks for your help in advance!</strong></p>