KODO:如何为双向关系设置获取计划?
运行 KODO 4.2 时遇到 KODO 生成查询效率低下的问题。当获取包含集合的对象时会发生这种情况,其中该集合与第一个对象具有双向关系。
Class Classroom
{
List<Student> _students;
}
Class Student
{
Classroom _classroom;
}
如果我们创建一个获取计划来通过设置以下获取计划来获取教室及其相应学生的列表:
fetchPlan.addField(Classroom.class,”_students”);
这将导致两个查询(获取教室,然后获取这些教室中的所有学生),这正是我们所期望的。
但是,如果我们在获取计划中包含对教室的引用,以便通过执行 fetchPlan.addField(Student.class, “_classroom”) 来填充 _classroom 字段,这将导致 X 数量的额外查询,其中 X是每个教室的学生人数。
谁能解释如何解决这个问题? KODO 在执行查询以检索 Classroom 对象并将它们设置在每个 Student 对象的 _classroom 字段中时已经拥有原始 Classroom 对象。所以我希望 KODO 简单地在每个 Student 对象的 _classroom 字段中相应地设置这些对象,而不是返回到数据库。
再说一遍,文档非常缺乏,但从我读到的内容来看,它应该能够更有效地做到这一点。
注意 - EAGER_FETCH.PARALLEL 已打开,我已在打开和关闭缓存(查询和数据缓存)的情况下尝试过此操作,结果查询没有任何差异。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与 Oracle 支持人员合作解决了这个问题——这是 Kodo 4.2(最新版本)中的一个缺陷。修复方法是从 jdo 元数据文件中为双向关系的一对一字段完全取出 default-fetch-group 属性(不要只是将其设置为 true 或 false)。因此,在上面的示例中,您将取出 Student._classroom 字段的 default-fetch-group 属性。
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.