HHH-5370 - Building IN condition with CriteriaBuilder providing collection of values not working.

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19930 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-07-10 13:48:34 +00:00
parent b50d8268d5
commit 21b68ef40f
2 changed files with 39 additions and 2 deletions

View File

@ -88,7 +88,7 @@ public abstract class ExpressionImpl<T>
* {@inheritDoc} * {@inheritDoc}
*/ */
public Predicate in(Collection<?> values) { public Predicate in(Collection<?> values) {
return criteriaBuilder().in( this, values ); return criteriaBuilder().in( this, values.toArray() );
} }
/** /**

View File

@ -25,11 +25,13 @@ package org.hibernate.ejb.criteria.basic;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Collections;
import java.util.List; import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.ParameterExpression; import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
@ -58,7 +60,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
product.setId( "product1" ); product.setId( "product1" );
product.setPrice( 1.23d ); product.setPrice( 1.23d );
product.setQuantity( 2 ); product.setQuantity( 2 );
product.setPartNumber( Integer.MAX_VALUE + 1 ); product.setPartNumber( ((long)Integer.MAX_VALUE) + 1 );
product.setRating( 1.999f ); product.setRating( 1.999f );
product.setSomeBigInteger( BigInteger.valueOf( 987654321 ) ); product.setSomeBigInteger( BigInteger.valueOf( 987654321 ) );
product.setSomeBigDecimal( BigDecimal.valueOf( 987654.321 ) ); product.setSomeBigDecimal( BigDecimal.valueOf( 987654.321 ) );
@ -248,4 +250,39 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
return hqlQueryImpl.getParameterMetadata().getNamedParameterNames().size(); return hqlQueryImpl.getParameterMetadata().getNamedParameterNames().size();
} }
public void testInExplicitTupleList() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
Root<Product> from = criteria.from( Product.class );
criteria.where( from.get( Product_.partNumber ).in( Collections.singletonList( ((long)Integer.MAX_VALUE) + 1 ) ) );
List<Product> result = em.createQuery( criteria ).getResultList();
assertEquals( 1, result.size() );
em.getTransaction().commit();
em.close();
}
public void testInExplicitTupleListVarargs() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
Root<Product> from = criteria.from( Product.class );
criteria.where( from.get( Product_.partNumber ).in( ((long)Integer.MAX_VALUE) + 1 ) );
List<Product> result = em.createQuery( criteria ).getResultList();
assertEquals( 1, result.size() );
em.getTransaction().commit();
em.close();
}
public void testInExpressionVarargs() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
Root<Product> from = criteria.from( Product.class );
criteria.where( from.get( Product_.partNumber ).in( from.get( Product_.partNumber ) ) );
List<Product> result = em.createQuery( criteria ).getResultList();
assertEquals( 1, result.size() );
em.getTransaction().commit();
em.close();
}
} }