title: What is the best practice to lazy-load model-objects in JSF
body: <p>I am developing a web-application, and want to use lazy loading in the models. 
  Therefore I have adapted the getter-methods and check if the value is null (and not loaded) and if so, it requests this value from the db.</p>
  
  <p>the problem is now, that if many values are not loaded at a point and I access them (the getter) e.g. from the xhtml-page, it creates lots of db-connections with each little queries inside.</p>
  
  <p>I am now wondering, how such a lazy-loaded model is implemented in big web-applications (e.g. e-commerce). Do they have a "pool" where all once data is cached so first the cache is checked and only then the db accessed? or is it better to use a applications-scoped DB-Connection which is permanently open so creating new connections is avoided?</p>
  
  <p>How should I implement my loading-strategy for models, which are loaded as needed on page access but lazy loads all additional elements?</p>
  
  <p>for example we have following chapter-structure in DB:</p>
  
  <ol>
  <li>chapter
  1.1 chapter
  1.2 chapter
  1.2.1 chapter</li>
  </ol>
  
  <p>The page "x" loads chapter 1.1, but without parent and children (only the name and its id). when the user opens it, it should load also the children (lazy) and so on...</p>