diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/queries/ReportQuery.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/queries/ReportQuery.java index 2b5df3cc169..38ba67f204a 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/queries/ReportQuery.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/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/main/java/org/eclipse/persistence/queries/ReportQueryResult.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/queries/ReportQueryResult.java index 7c4f5640007..9bfcd7d4954 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/queries/ReportQueryResult.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/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 @@ -250,9 +250,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);