title: hibernate, to be lazy or not to be lazy?
body: <p>I have <code>entity A</code>, which has a many-to-many relation to <code>entity B</code>. </p>
  
  <p>So the table layout is :     <code>A, AB(mapping table), B</code></p>
  
  <p>To get an object of entity A: 
  I call <code>A.getById()</code> which does <code>getHibernateTemplate().get(A.class, id)</code>   using spring and hibernate.  </p>
  
  <p>The problem is, sometimes ensuing code will just need A, sometimes  ensuing code will continue to access the associated B's, so we'd like to use <strong>lazy loading</strong> in some cases and <strong>eager</strong> in some other cases. but the problem is that all database access is provided through the same single <code>ADao.java</code>, so there is only one method <code>getById()</code>.</p>
  
  <p><strong>Should I create two versions of method getById()?</strong></p>
  
  <p>But then for more complex cases, if A is also attached to C through many-to-many, then there could be variants of lazy-loading-C and eager-loading-C,so the required <code>getById()</code> variants quickly grows exponentially.</p>
  
  <p>what is your opinion on this choice?</p>
  
  <p>Thanks</p>