Skip to content

Bug 544995 : Fixed batch fetching when shared cache is activated #378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
// - 389090: JPA 2.1 DDL Generation Support (foreign key metadata support)
// 08/12/2015-2.6 Mythily Parthasarathy
// - 474752: Address NPE for Embeddable with 1-M association
// 04/19/2020-3.0 Alexandre Jacob
// - 544995: Fixed batch fetching when shared cache is activated (multithreading issue)
package org.eclipse.persistence.mappings;

import java.security.AccessController;
Expand Down Expand Up @@ -540,6 +542,9 @@ public Object extractResultFromBatchQuery(ReadQuery batchQuery, CacheKey parentC
// If the object is already in the cache, then just return it.
return cachedObject;
}

boolean shouldExecuteBatchQuery = true;

// Ensure the query is only executed once.
synchronized (batchQuery) {
// Check if query was already executed.
Expand Down Expand Up @@ -637,15 +642,24 @@ public Object extractResultFromBatchQuery(ReadQuery batchQuery, CacheKey parentC
originalPolicy.setDataResults(this, remainingParentRows);
translationRow = translationRow.clone();
translationRow.put(QUERY_BATCH_PARAMETER, foreignKeyValues);

if (foreignKeyValues.isEmpty()) {
shouldExecuteBatchQuery = false;
}

// Register each id as null, in case it has no relationship.
for (Object foreignKey : foreignKeys) {
batchedObjects.put(foreignKey, Helper.NULL_VALUE);
}
} else if (batchQuery.isReadAllQuery() && ((ReadAllQuery)batchQuery).getBatchFetchPolicy().isIN()) {
throw QueryException.originalQueryMustUseBatchIN(this, originalQuery);
}
executeBatchQuery(batchQuery, parentCacheKey, batchedObjects, session, translationRow);
batchQuery.setSession(null);

// Bug 544995 : When the cache is populated by another thread we can end up having nothing to fetch
if (shouldExecuteBatchQuery) {
executeBatchQuery(batchQuery, parentCacheKey, batchedObjects, session, translationRow);
batchQuery.setSession(null);
}
}
result = batchedObjects.get(sourceKey);
if (result == Helper.NULL_VALUE) {
Expand Down