[ https://issues.apache.org/jira/browse/OPENJPA-717?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12628492#action_12628492 ] Xiaoqin Feng commented on OPENJPA-717: -------------------------------------- In JDBCStoreManager.selectBaseMappings(), it recursively call parent class selectBaseMappings(). For one-to-one relationship in parent class fms[i].selectEagerJoin(sel, sm, this, fetch.traverseJDBC(fms[i]), eager) is called so join is added to join set. When recursive call returns to subclass, sub-super join will add to join sets. That is the result you see in the first SQL. For one-to-many relation, it calls fms[i].selectEagerParallel(esel, sm, this, fetch.traverseJDBC(fms[i]), eager); In current code design, it uses SelectExecutor and start with new join set in StoreCollectionFieldStrategy.selectEager(). So there is no way to have sub-super join info for one-to-many relation. I will attach a test case later. > OpenJPA doesn't generate SQL with efficient joins when joined inheritance strategy is used and there is one-many relation in superclass > --------------------------------------------------------------------------------------------------------------------------------------- > > Key: OPENJPA-717 > URL: https://issues.apache.org/jira/browse/OPENJPA-717 > Project: OpenJPA > Issue Type: Improvement > Components: query > Affects Versions: 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.1.0, 1.2.0 > Reporter: Xiaoqin Feng > > The test case has a subclass that extends an abstract superclass that > basically contains a single additional field 'S1', a one-to-one relation 'superOne' and a one-to-many relation 'superMany'. The superclass has an > inheritance strategy of 'JOINED'. > When executing the query: > SELECT s FROM Subclass s WHERE s.a1 = :a1 > three SQL statements get generated: > SELECT t1.ID, t0.id, t1.S1, t2.ID, t2.S1, t0.A1, t3.ID, t3.A1 > FROM SUBCLASS t0, SUPERCLASS t1, SUPERCLASSONE t2, SUBCLASSONE t3 > WHERE (t0.A1 = ?) AND t0.SUBCLASSONE_ID = t3.ID(+) AND t0.id = t1.ID AND > t1.SUPERCLASSONE_ID = t2.ID(+) > SELECT t0.id, t1.ID, t1.A1 > FROM SUBCLASS t0, SUBCLASSMANY t1 > WHERE (t0.A1 = ?) AND t0.id = t1.SUBCLASS_ID ORDER BY t0.id ASC > SELECT t1.ID, t2.ID, t2.S1 > FROM SUBCLASS t0, SUPERCLASS t1, SUPERCLASSMANY t2 > WHERE (t0.A1 = ?) AND t1.ID = t2.SUPERCLASS_ID ORDER BY t1.ID ASC > The third one doesn't contain the condition t0.ID = t1.ID > Although final returned result set is correct because of the logical union, the third SQL returns more rows so it has bad performance. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.