KODO: how set up fetch plan for bidirectional relationships?

320 views Asked by At

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.

Class Classroom
{
     List<Student> _students; 
}

Class Student
{
     Classroom _classroom;
}

If we create a fetch plan to get a list of Classrooms and their corresponding Students by setting up the following fetch plan:

fetchPlan.addField(Classroom.class,”_students”);

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.

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.

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.

Once again, the documentation is sorely lacking but from what I've read it should be able to do this more efficiently.

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.

1

There are 1 answers

0
BestPractices On BEST ANSWER

Worked with Oracle Support on this-- this is a defect in Kodo 4.2 (the latest version). Fix is to take out default-fetch-group attribute COMPLETELY (dont just set it to true or false) from the jdo metadata file for the fields that are on the one-to-one side of the bidirectional relationship. So in the example above, you would take out the default-fetch-group attribute for the Student._classroom field.