HHH-8556 QueryStructure#collectCorrelatedJoins should add

correlationRoots implementing Join
This commit is contained in:
Brett Meyer 2013-09-25 12:09:33 -04:00
parent 9e5ba931fb
commit a20b0bd9ea
2 changed files with 27 additions and 2 deletions

View File

@ -172,6 +172,9 @@ public class QueryStructure<T> implements Serializable {
if ( correlationRoots != null ) {
correlatedJoins = new HashSet<Join<?,?>>();
for ( FromImplementor<?,?> correlationRoot : correlationRoots ) {
if (correlationRoot instanceof Join<?,?> && correlationRoot.isCorrelated()) {
correlatedJoins.add( (Join<?,?>) correlationRoot );
}
correlatedJoins.addAll( correlationRoot.getJoins() );
}
}

View File

@ -23,15 +23,18 @@
*/
package org.hibernate.jpa.test.criteria.subquery;
import static org.junit.Assert.assertEquals;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CollectionJoin;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Subquery;
import org.junit.Test;
import org.hibernate.dialect.SybaseASE15Dialect;
import org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest;
import org.hibernate.jpa.test.metamodel.Customer;
@ -41,11 +44,14 @@ import org.hibernate.jpa.test.metamodel.LineItem_;
import org.hibernate.jpa.test.metamodel.Order;
import org.hibernate.jpa.test.metamodel.Order_;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
/**
* @author Steve Ebersole
*/
public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
@Test
public void testBasicCorrelation() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
@ -132,6 +138,22 @@ public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
em.getTransaction().commit();
em.close();
}
@Test
@TestForIssue(jiraKey = "HHH-8556")
public void testCorrelatedJoinsFromSubquery() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
CriteriaQuery<Customer> cquery = builder.createQuery(Customer.class);
Root<Customer> customer = cquery.from(Customer.class);
cquery.select(customer);
Subquery<Order> sq = cquery.subquery(Order.class);
Join<Customer, Order> sqo = sq.correlate(customer.join(Customer_.orders));
sq.select(sqo);
Set<Join<?, ?>> cJoins = sq.getCorrelatedJoins();
// ensure the join is returned in #getCorrelatedJoins
assertEquals( cJoins.size(), 1);
}
@Test
public void testVariousSubqueryJoinSemantics() {