HHH-4583 - Incorrect handling of empty conjunction and disjunction

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18823 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-02-17 21:07:42 +00:00
parent d7de0dad4e
commit 5a4e37495e
2 changed files with 16 additions and 3 deletions

View File

@ -116,9 +116,9 @@ public class CompoundPredicate
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) { public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
if ( getExpressions().size() == 0 ) { if ( getExpressions().size() == 0 ) {
return getOperator() == Predicate.BooleanOperator.AND return getOperator() == BooleanOperator.AND
? "true" ? "1=1" // true
: "false"; : "0=1"; // false
} }
if ( getExpressions().size() == 1 ) { if ( getExpressions().size() == 1 ) {
return ( (Renderable) getExpressions().get(0) ).render( renderingContext ); return ( (Renderable) getExpressions().get(0) ).render( renderingContext );

View File

@ -25,6 +25,7 @@ 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.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
@ -69,6 +70,18 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
super.tearDown(); super.tearDown();
} }
public void testEmptyConjunction() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
criteria.from( Product.class );
criteria.where( builder.and() );
List<Product> result = em.createQuery( criteria ).getResultList();
assertEquals( 1, result.size() );
em.getTransaction().commit();
em.close();
}
public void testDiff() { public void testDiff() {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin(); em.getTransaction().begin();