Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 360991 - Use TYPE expression to limit joins/calls with joined inheritance on a root entity
Summary: Use TYPE expression to limit joins/calls with joined inheritance on a root en...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-14 11:44 EDT by Chris Delahunt CLA
Modified: 2022-06-09 10:29 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Delahunt CLA 2011-10-14 11:44:55 EDT
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).
Comment 1 Kok-Wai Looi CLA 2012-10-29 12:22:43 EDT
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.
Comment 2 Chris Delahunt CLA 2012-10-29 14:14:37 EDT
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.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:29:26 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink