Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 360728

Summary: QueryHints.BATCH queries are not (always) executed if there is a FetchType.Lazy annotation value on the collection
Product: z_Archived Reporter: Martin Marinschek <martin.marinschek>
Component: EclipselinkAssignee: Project Inbox <eclipselink.orm-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P2 CC: jamesssss, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Martin Marinschek CLA 2011-10-12 16:44:17 EDT
Build Identifier: 2.2.1

See the following code:

ForeignReferenceMapping#batchedValueFromRow:

    protected Object batchedValueFromRow(AbstractRecord row, ObjectLevelReadQuery query, CacheKey parentCacheKey) {
        ReadQuery batchQuery = (ReadQuery)query.getProperty(this);
        if (batchQuery == null) {
            if (query.hasBatchReadAttributes()) {
                Map<DatabaseMapping, ReadQuery> queries = query.getBatchFetchPolicy().getMappingQueries();
                if (queries != null) {
                    batchQuery = queries.get(this);
                }
            }
            if (batchQuery == null) {
                batchQuery = prepareNestedBatchQuery(query);
                batchQuery.setIsExecutionClone(true);
            } else {
                batchQuery = (ReadQuery)batchQuery.clone();
                batchQuery.setIsExecutionClone(true);
            }
            query.setProperty(this, batchQuery);
        }
        return this.indirectionPolicy.valueFromBatchQuery(batchQuery, row, query, parentCacheKey);
    }

this references the indirection-policy for this mapping. Depending on the annotations, this indirection-policy might be set for lazy fetching. However, if I specify a Batch QueryHint, my assumption would be that the batch is always executed, and the annotations are disregarded.

Reproducible: Always
Comment 1 Tom Ware CLA 2011-10-13 13:33:30 EDT
Where are you expecting to see the batch query?  On the initial call, or when the LAZY relationship is triggered?

Batch queries should run when the relationship is triggered.  For EAGER relationships that will be right away, but for LAZY relationships, it will occur when the relationship is first traversed.
Comment 2 Tom Ware CLA 2011-10-31 13:23:38 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 3 James Sutherland CLA 2013-07-09 15:23:35 EDT
No, batch fetching supports LAZY.  If you want the relationships instantiated, the specify a LoadGroup.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:04:55 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:10:23 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink