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