HHH-9374 EntityGraph applied to subquery when using collection function

(cherry picked from commit 1677e0662b)
This commit is contained in:
Réda Housni Alaoui 2015-08-30 01:49:54 +02:00 committed by Steve Ebersole
parent c84cc32297
commit 3da8d8542f
2 changed files with 20 additions and 2 deletions

View File

@ -7,6 +7,7 @@
package org.hibernate.engine.query.spi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -52,7 +53,8 @@ public class EntityGraphQueryHint {
}
return getFromElements(
originEntityGraph.getAttributeNodes(),
fromClause.getLevel() == FromClause.ROOT_LEVEL ? originEntityGraph.getAttributeNodes():
Collections.emptyList(),
fromClause.getFromElement(),
fromClause,
walker,

View File

@ -281,7 +281,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
// Ensure the EntityGraph and explicit fetches do not conflict.
Query query = entityManager.createQuery( "from " + Company.class.getName()
+ " as c left join fetch c.location left join fetch c.employees where c.location.zip = :zip")
.setParameter( "zip", 12345 );
.setParameter("zip", 12345);
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
Company company = (Company) query.getSingleResult();
@ -296,6 +296,22 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
assertTrue( Hibernate.isInitialized( company.phoneNumbers ) );
}
@Test
@TestForIssue(jiraKey = "HHH-9374")
public void testEntityGraphWithCollectionSubquery(){
EntityManager entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
EntityGraph<Company> entityGraph = entityManager.createEntityGraph(Company.class);
entityGraph.addAttributeNodes("location");
Query query = entityManager.createQuery("select c from " + Company.class.getName() + " c where c.employees IS EMPTY");
query.setHint(QueryHints.HINT_LOADGRAPH, entityGraph);
query.getResultList();
entityManager.getTransaction().commit();
entityManager.close();
}
@Before
public void createData() {
EntityManager entityManager = getOrCreateEntityManager();