From 5a4e37495e3c12a51659776069a0100d0fb1dc90 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 17 Feb 2010 21:07:42 +0000 Subject: [PATCH] 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 --- .../ejb/criteria/predicate/CompoundPredicate.java | 6 +++--- .../ejb/criteria/basic/ExpressionsTest.java | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java b/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java index 516a275997..d55c51b734 100644 --- a/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java +++ b/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java @@ -116,9 +116,9 @@ public class CompoundPredicate public String render(CriteriaQueryCompiler.RenderingContext renderingContext) { if ( getExpressions().size() == 0 ) { - return getOperator() == Predicate.BooleanOperator.AND - ? "true" - : "false"; + return getOperator() == BooleanOperator.AND + ? "1=1" // true + : "0=1"; // false } if ( getExpressions().size() == 1 ) { return ( (Renderable) getExpressions().get(0) ).render( renderingContext ); diff --git a/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java b/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java index 75d652a8e5..1e65eda44b 100644 --- a/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java +++ b/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java @@ -25,6 +25,7 @@ package org.hibernate.ejb.criteria.basic; import java.math.BigDecimal; import java.math.BigInteger; +import java.util.List; import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; @@ -69,6 +70,18 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { super.tearDown(); } + public void testEmptyConjunction() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + CriteriaQuery criteria = builder.createQuery( Product.class ); + criteria.from( Product.class ); + criteria.where( builder.and() ); + List result = em.createQuery( criteria ).getResultList(); + assertEquals( 1, result.size() ); + em.getTransaction().commit(); + em.close(); + } + public void testDiff() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin();