From 180e714b7c47fe0a1f20d60cacc7fdc129dd7b0b Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Thu, 19 Mar 2015 21:58:30 -0700 Subject: [PATCH] HHH-9448 : Association is not fetched when EntityGraph has explicit fetch and query has implicit join --- .../engine/query/spi/EntityGraphQueryHint.java | 13 ++++++++++--- .../graphs/queryhint/QueryHintEntityGraphTest.java | 1 - 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/EntityGraphQueryHint.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/EntityGraphQueryHint.java index 4d87976523..4356100302 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/EntityGraphQueryHint.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/EntityGraphQueryHint.java @@ -95,8 +95,9 @@ public class EntityGraphQueryHint { final Type propertyType = origin.getPropertyType( attributeName, attributeName ); try { - FromElement fromElement = null; - if ( !explicitFetches.containsKey( role ) ) { + FromElement fromElement = explicitFetches.get( role ); + boolean explicitFromElement = false; + if ( fromElement == null ) { if ( propertyType.isEntityType() ) { final EntityType entityType = (EntityType) propertyType; @@ -137,10 +138,16 @@ public class EntityGraphQueryHint { queryableCollection, collectionType.getRole(), JoinType.LEFT_OUTER_JOIN, true, false ); } + } else { + explicitFromElement = true; + fromElement.setInProjectionList( true ); + fromElement.setFetch( true ); } if ( fromElement != null ) { - fromElements.add( fromElement ); + if( !explicitFromElement ){ + fromElements.add( fromElement ); + } // recurse into subgraphs for ( Subgraph subgraph : attributeNode.getSubgraphs().values() ) { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/queryhint/QueryHintEntityGraphTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/queryhint/QueryHintEntityGraphTest.java index 43f5356ac0..65dc5b7ab0 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/queryhint/QueryHintEntityGraphTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/queryhint/QueryHintEntityGraphTest.java @@ -191,7 +191,6 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas @Test @TestForIssue( jiraKey = "HHH-9448") - @FailureExpected( jiraKey = "HHH-9448") public void testLoadGraphWithRestriction() { EntityManager entityManager = getOrCreateEntityManager(); entityManager.getTransaction().begin();