HHH-4772 - Empty conjunction/disjunction in criteria does not follow spec rules
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18483 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
5263d4c12a
commit
20b78f45a7
|
@ -115,6 +115,11 @@ public class CompoundPredicate
|
|||
}
|
||||
|
||||
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
|
||||
if ( getExpressions().size() == 0 ) {
|
||||
return getOperator() == Predicate.BooleanOperator.AND
|
||||
? "true"
|
||||
: "false";
|
||||
}
|
||||
if ( getExpressions().size() == 1 ) {
|
||||
return ( (Renderable) getExpressions().get(0) ).render( renderingContext );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.ejb.criteria.basic;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
||||
import org.hibernate.ejb.metamodel.Order;
|
||||
|
||||
/**
|
||||
* Test the various predicates.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class PredicateTest extends AbstractMetamodelSpecificTest {
|
||||
public void testEmptyConjunction() {
|
||||
// yes this is a retarded case, but explicitly allowed in the JPA spec
|
||||
CriteriaBuilder builder = factory.getCriteriaBuilder();
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
|
||||
Root<Order> orderRoot = orderCriteria.from(Order.class);
|
||||
orderCriteria.select(orderRoot);
|
||||
orderCriteria.where( builder.isTrue( builder.conjunction() ) );
|
||||
em.createQuery( orderCriteria ).getResultList();
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testEmptyDisjunction() {
|
||||
// yes this is a retarded case, but explicitly allowed in the JPA spec
|
||||
CriteriaBuilder builder = factory.getCriteriaBuilder();
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
|
||||
Root<Order> orderRoot = orderCriteria.from(Order.class);
|
||||
orderCriteria.select(orderRoot);
|
||||
orderCriteria.where( builder.isFalse( builder.disjunction() ) );
|
||||
em.createQuery( orderCriteria ).getResultList();
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue