Alright, I stopped complaining and started work at solving this problem. I 
created https://issues.apache.org/jira/browse/OPENJPA-2296 and I started 
debugging the issue with the Eclipse debugger to localize the problem.

I suspect that the bug is inside JDBCStoreManager.createEagerSelects(). This is 
the method that determines the list of Eager relations that is shown in the 
trace. When Project - Employee is toOne it does consider Employee.projects but 
somehow skips it. One theory I have is that it thinks this relation is a toOne 
relation as well, but of course this is a toMany. When Company - Employee is 
toMany, this same code does not skip the relation and adds it as eager.

I think at a high level in the EagerResultList we then see the consequence: the 
project relations are not yet fetched inside the "main query" of 
ResultObjectProvider.open(). After this, the while loop of EagerResultList adds 
entities and each call to load an Employee entity has to do an actual database 
load instead of reusing the entities that should be present in the context.

I think someone more familiar with JDBCStoreManager now already has good 
directions of finding and fixing the problem and perhaps with the consequences 
of a fix.

I will try and debug some more and add my results as comments to OPENJPA-2296.

Reply via email to