diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ReportQuery.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ReportQuery.java index 7bd6d9c6a1f..9c2f9e281c8 100644 --- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ReportQuery.java +++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ReportQuery.java @@ -891,7 +891,12 @@ public Object executeDatabaseQuery() throws DatabaseException { return getDescriptor().getInterfacePolicy().selectAllObjectsUsingMultipleTableSubclassRead(this); } - return buildObjects(getQueryMechanism().selectAllReportQueryRows()); + List rows = getQueryMechanism().selectAllReportQueryRows(); + if ((this.batchFetchPolicy != null) && this.batchFetchPolicy.isIN()) { + this.batchFetchPolicy.setDataResults(rows); + } + + return buildObjects((Vector) rows); } /** diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ReportQueryResult.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ReportQueryResult.java index f72bfe34487..326203dbc30 100644 --- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ReportQueryResult.java +++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ReportQueryResult.java @@ -1,6 +1,6 @@ /* - * Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2019, 2020 IBM Corporation. All rights reserved. + * Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024 IBM Corporation. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -239,9 +239,26 @@ protected Object processItem(ReportQuery query, AbstractRecord row, Vector toMan AbstractRecord subRow = row; // Check if at the start of the row, then avoid building a subRow. if (itemIndex > 0) { - Vector trimedFields = new NonSynchronizedSubVector(row.getFields(), itemIndex, rowSize); - Vector trimedValues = new NonSynchronizedSubVector(row.getValues(), itemIndex, rowSize); - subRow = new DatabaseRecord(trimedFields, trimedValues); + BatchFetchPolicy batchFetchPolicy = query.getBatchFetchPolicy(); + if (batchFetchPolicy != null && batchFetchPolicy.isIN()) { + + List subRows = new ArrayList(toManyData.size()); + for (AbstractRecord parentRow : (Vector) toManyData) { + Vector trimedParentFields = new NonSynchronizedSubVector<>(parentRow.getFields(), itemIndex, rowSize); + Vector trimedParentValues = new NonSynchronizedSubVector<>(parentRow.getValues(), itemIndex, rowSize); + subRows.add(new DatabaseRecord(trimedParentFields, trimedParentValues)); + } + + for (DatabaseMapping subMapping : descriptor.getMappings()) { + batchFetchPolicy.setDataResults(subMapping, subRows); + } + + subRow = subRows.get(toManyData.indexOf(row)); + } else { + Vector trimedFields = new NonSynchronizedSubVector(row.getFields(), itemIndex, rowSize); + Vector trimedValues = new NonSynchronizedSubVector(row.getValues(), itemIndex, rowSize); + subRow = new DatabaseRecord(trimedFields, trimedValues); + } } if (mapping != null && mapping.isAggregateObjectMapping()){ value = ((AggregateObjectMapping)mapping).buildAggregateFromRow(subRow, null, null, joinManager, query, false, query.getSession(), true);