title: KODO: how set up fetch plan for bidirectional relationships?
body: <p>Running KODO 4.2 and having an issue inefficient queries being generated by KODO. This happens when fetching an object that contains a collection where that collection has a bidrectional relationship back to the first object. </p>
  
  <pre><code>Class Classroom
  {
       List&lt;Student&gt; _students; 
  }
  
  Class Student
  {
       Classroom _classroom;
  }
  </code></pre>
  
  <p>If we create a fetch plan to get a list of Classrooms and their corresponding Students by setting up the following fetch plan:</p>
  
  <p>fetchPlan.addField(Classroom.class,”_students”); </p>
  
  <p>This will result in two queries (get the classrooms and then get all students that are in those classrooms), which is what we would expect.</p>
  
  <p>However, if we include the reference back to the classroom in our fetch plan in order for the _classroom field to get populated by doing fetchPlan.addField(Student.class, “_classroom”), this will result in X number of additional queries where X is the number of students in each classroom. </p>
  
  <p>Can anyone explain how to fix this? KODO already has the original Classroom objects at the point that it's executing the queries to retrieve the Classroom objects and set them in each Student object's _classroom field. So I would expect KODO to simply set those objects in the _classroom field on each Student object accordingly and not go back to the database.</p>
  
  <p>Once again, the documentation is sorely lacking but from what I've read it should be able to do this more efficiently. </p>
  
  <p>Note-- EAGER_FETCH.PARALLEL is turned on and I have tried this with caching (query and data caches) turned on and off and there is no difference in the resultant queries.</p>