I'm having some strange RDBMS N+1 calls most likely due to my mappings, but am not sure if this is a DN Persistence configuration issue or a mapping issue. I'm using MSSQL.
My problem is that I have an Object "Person" which has some audit fields "addPerson" and "modPerson". Both "addPerson" and "modPerson" are simple N-1 relations. Conceptually like the following:
// InheritanceStrategy=New-table
Class Person extends Audit{
String name;
int age;
}
// InheritanceStrategy=subclass-table
Class Audit{
AuditPerson addPerson;
AuditPerson modPerson;
}
Class AuditPerson{
String username;
}
When I retrieve the Person (using a datastore identity), I see an SQL Query which selects the primitive fields but not the embedded Objects. Something like:
"
Select name, age FROM Person where ID = 123".
When I try to convert to a DTO and read the `addPerson`, and `modPerson` fields, DN then launches the next queries:
- select addPerson FROM Person where ID =123
- select username FROM AuditPerson where ID = <>
- select modPerson FROM Person where ID =123
- select username FROM AuditPerson where ID = <>
So, essentially, because of the "lazy loading", it needs to requery the DB for the 2 FK values in the Person table before it can actually query the AuditPerson table.
Clearly, I suspect that this is due to issues in my mapping definitions. I am working with old mapping files from Kodo, so I suspect there is something I haven't done correctly.
Questions:
1) Is this normal/expected behaviour? Is this due to the inheriteance model/hierarchy?
2) Is this controllable via mapping configurations?
3) Is there a way to reconfigure the model such that I do not need the additonal independent queries to retrieve the FK values for the modPerson and addPerson.
I realize that this is difficult to diagnose without exact details and sample test case, but thought I would ask in the meantime while I try to reproduce the exact behaviour in a test app in case someone has seen/experienced this before.
Thanks,
Eric