Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Lazy fetching strategy lets you decide how much of the object graph should be loaded in the first database hit and which associations should be loaded lazily. And you are using DTO to transfer the objects from persistance layer to service layer.They are two completely different concepts. One is to load data from DB and the other is to transfer data among different layers. </p> <p>Now for lazy loading, the recommended way is to configure all the associations for lazy fetching in the mapping file(with <code>lazy="true"</code>), which may then be overridden at runtime (wherever these is a need of an eager fetching). </p> <p>Lets consider these two scenarios:</p> <ul> <li><p>There may be a need to fetch a list of the <code>Sections</code> (but you don't want the <code>associations</code> of the individual <code>Sections</code> objects to be loaded):</p></li> </ul> <p>This list can be fetched using</p> <pre><code>session.createQuery("from Sections sections"); </code></pre> <p>where the <code>Sections</code> present in the returned <code>list</code> will not contain the <code>associations</code>.</p> <ul> <li><p>You may again want to fetch a list of <code>Sections</code> with the associations fetched eagerly. This can be achieved by an outer join using the <code>fetch</code> keyword in the <code>from</code> clause (overriding the default fetching behavior):</p></li> </ul> <blockquote> <p>session.createQuery("from Sections sections left join fetch sections.association-name");</p> </blockquote> <p>When executed, this will return a list of Section instances, with its associations fully initialized.</p> <p>Now, once you have the data loaded, you can use the DTOs to transfer the data to the service layer.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload