|
23 | 23 | // - 389090: JPA 2.1 DDL Generation Support (foreign key metadata support)
|
24 | 24 | // 08/12/2015-2.6 Mythily Parthasarathy
|
25 | 25 | // - 474752: Address NPE for Embeddable with 1-M association
|
| 26 | +// 04/19/2020-3.0 Alexandre Jacob |
| 27 | +// - 544995: Fixed batch fetching when shared cache is activated (multithreading issue) |
26 | 28 | package org.eclipse.persistence.mappings;
|
27 | 29 |
|
28 | 30 | import java.security.AccessController;
|
@@ -540,6 +542,9 @@ public Object extractResultFromBatchQuery(ReadQuery batchQuery, CacheKey parentC
|
540 | 542 | // If the object is already in the cache, then just return it.
|
541 | 543 | return cachedObject;
|
542 | 544 | }
|
| 545 | + |
| 546 | + boolean shouldExecuteBatchQuery = true; |
| 547 | + |
543 | 548 | // Ensure the query is only executed once.
|
544 | 549 | synchronized (batchQuery) {
|
545 | 550 | // Check if query was already executed.
|
@@ -637,15 +642,24 @@ public Object extractResultFromBatchQuery(ReadQuery batchQuery, CacheKey parentC
|
637 | 642 | originalPolicy.setDataResults(this, remainingParentRows);
|
638 | 643 | translationRow = translationRow.clone();
|
639 | 644 | translationRow.put(QUERY_BATCH_PARAMETER, foreignKeyValues);
|
| 645 | + |
| 646 | + if (foreignKeyValues.isEmpty()) { |
| 647 | + shouldExecuteBatchQuery = false; |
| 648 | + } |
| 649 | + |
640 | 650 | // Register each id as null, in case it has no relationship.
|
641 | 651 | for (Object foreignKey : foreignKeys) {
|
642 | 652 | batchedObjects.put(foreignKey, Helper.NULL_VALUE);
|
643 | 653 | }
|
644 | 654 | } else if (batchQuery.isReadAllQuery() && ((ReadAllQuery)batchQuery).getBatchFetchPolicy().isIN()) {
|
645 | 655 | throw QueryException.originalQueryMustUseBatchIN(this, originalQuery);
|
646 | 656 | }
|
647 |
| - executeBatchQuery(batchQuery, parentCacheKey, batchedObjects, session, translationRow); |
648 |
| - batchQuery.setSession(null); |
| 657 | + |
| 658 | + // Bug 544995 : When the cache is populated by another thread we can end up having nothing to fetch |
| 659 | + if (shouldExecuteBatchQuery) { |
| 660 | + executeBatchQuery(batchQuery, parentCacheKey, batchedObjects, session, translationRow); |
| 661 | + batchQuery.setSession(null); |
| 662 | + } |
649 | 663 | }
|
650 | 664 | result = batchedObjects.get(sourceKey);
|
651 | 665 | if (result == Helper.NULL_VALUE) {
|
|
0 commit comments