Community
Participate
Working Groups
When querying on a parent entity with joined-table inheritance, EclipseLink (through JPA defaults, or using the read-subclasses option) will either use outer joins to join all entity tables in the tree, or use multiple calls for the various entities. If a query is known to only touch a particular entity (such as if the TYPE expression limits it), it is not neccessary and undesirable to outer join the excluded tables when outer joining is used. When it is not used, the first call to select possible subclasses is also not needed. This is of particular concern when FirstRows or maxresults is specified, as an outerjoin must be used to return the correct number in a single query/call (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=253258 for details).
Hi Chris, I am referring to your comments in http://myforums.oracle.com/jive3/thread.jspa?threadID=868053&tstart=0. Assume that the class hierarchy is as such: Equipment > CiscoEquipment > CiscoRouter. (> = "parent class of") I know if we have queried for the base Equipment class, EL would automatically add the subclasses CiscoEquipment and CiscoRouter as outer joins, especially when we use range. If the query is for CiscoEquipment however, would there still be any outer join at least to the CiscoRouter subclass? I assume if the query result class is for CiscoRouter then there is no more join generated because only that subclass is requested. What happens if we set "ClassDescriptor.getDescriptorInheritancePolicy().setShouldReadSubclasses(false)". When we execute explicit query for Equipment, CiscoEquipment, or CiscoRouter classes, is it true that since this descriptor property is set to false there should be no outer join generated but we have to also expect that some rows would be missing from the results because of the joins being removed. Thanks.
The EclipseLink user mailing list (eclipselink-users@eclipse.org) or the forums might be a better place to to questions. JPA requires selecting all subclasses when you query on a parent class type, so queries on CiscoEquipment will require bringing back CiscoRouter entities as well. EclipseLink will use outerjoining if counts/pagination is involved. I've not tried using setShouldReadSubclasses(false) but it looks like it will prevent this behavior. This setting will force queries on Equipment to return only Equipment instances - and exclude data that might be in CiscoEquipment and CiscoRouter. You would then need to query on each subclass explicitly to get those results if required.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink