HHH-9374 EntityGraph applied to subquery when using collection function
(cherry picked from commit 1677e0662b
)
This commit is contained in:
parent
c84cc32297
commit
3da8d8542f
|
@ -7,6 +7,7 @@
|
||||||
package org.hibernate.engine.query.spi;
|
package org.hibernate.engine.query.spi;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -52,7 +53,8 @@ public class EntityGraphQueryHint {
|
||||||
}
|
}
|
||||||
|
|
||||||
return getFromElements(
|
return getFromElements(
|
||||||
originEntityGraph.getAttributeNodes(),
|
fromClause.getLevel() == FromClause.ROOT_LEVEL ? originEntityGraph.getAttributeNodes():
|
||||||
|
Collections.emptyList(),
|
||||||
fromClause.getFromElement(),
|
fromClause.getFromElement(),
|
||||||
fromClause,
|
fromClause,
|
||||||
walker,
|
walker,
|
||||||
|
|
|
@ -281,7 +281,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
// Ensure the EntityGraph and explicit fetches do not conflict.
|
// Ensure the EntityGraph and explicit fetches do not conflict.
|
||||||
Query query = entityManager.createQuery( "from " + Company.class.getName()
|
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")
|
+ " 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 );
|
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
|
||||||
Company company = (Company) query.getSingleResult();
|
Company company = (Company) query.getSingleResult();
|
||||||
|
|
||||||
|
@ -296,6 +296,22 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
assertTrue( Hibernate.isInitialized( company.phoneNumbers ) );
|
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
|
@Before
|
||||||
public void createData() {
|
public void createData() {
|
||||||
EntityManager entityManager = getOrCreateEntityManager();
|
EntityManager entityManager = getOrCreateEntityManager();
|
||||||
|
|
Loading…
Reference in New Issue