HHH-8444 - Fix criteriaapi failures from JPA 2.1 TCK

This commit is contained in:
Steve Ebersole 2013-08-16 11:54:31 -05:00
parent d5ceb60062
commit 7bdcdca439
2 changed files with 49 additions and 1 deletions

View File

@ -194,11 +194,19 @@ public abstract class AbstractFromImpl<Z,X>
@Override
public boolean isCorrelated() {
return getCorrelationParent() != null;
return correlationParent != null;
}
@Override
public FromImplementor<Z,X> getCorrelationParent() {
if ( correlationParent == null ) {
throw new IllegalStateException(
String.format(
"Criteria query From node [%s] is not part of a subquery correlation",
getPathIdentifier()
)
);
}
return correlationParent;
}

View File

@ -38,12 +38,52 @@ import org.hibernate.jpa.test.metamodel.Order_;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
/**
* @author Steve Ebersole
*/
public class UncorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
@Test
public void testGetCorrelatedParentIllegalStateException() {
// test that attempting to call getCorrelatedParent on a uncorrelated query/subquery
// throws ISE
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Customer> criteria = builder.createQuery( Customer.class );
Root<Customer> customerRoot = criteria.from( Customer.class );
Join<Customer, Order> orderJoin = customerRoot.join( Customer_.orders );
criteria.select( customerRoot );
Subquery<Double> subCriteria = criteria.subquery( Double.class );
Root<Order> subqueryOrderRoot = subCriteria.from( Order.class );
subCriteria.select( builder.min( subqueryOrderRoot.get( Order_.totalPrice ) ) );
criteria.where( builder.equal( orderJoin.get( "totalPrice" ), builder.all( subCriteria ) ) );
assertFalse( customerRoot.isCorrelated() );
assertFalse( subqueryOrderRoot.isCorrelated() );
try {
customerRoot.getCorrelationParent();
fail( "Should have resulted in IllegalStateException" );
}
catch (IllegalStateException expected) {
}
try {
subqueryOrderRoot.getCorrelationParent();
fail( "Should have resulted in IllegalStateException" );
}
catch (IllegalStateException expected) {
}
em.getTransaction().commit();
em.close();
}
@Test
public void testEqualAll() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();