Community
Participate
Working Groups
Build Identifier: 2.0.2.v20100323-r6872 when using isNull() and isNotNull() the and() method does not correctly and-together two parameters. e.g. little code snippet: criteriaList.add(builder.isNotNull(from.get(Rating_.ratOutputValue))); criteriaList.add(builder.isNotNull(from.get(Rating_.ratOutputValueunitId))); criteriaList.add(builder.isNull(outerJoin.get(SomeEntity_.someId))); Predicate criteria = builder.and(criteriaList.toArray(new Predicate[0])); cq.select(from).where(criteria); in the resulting SQL-String only one criteria is queried (3 were expected) If the criteria's are built with the "less-readable" notEqual() or equal() all 3 parameters are queried by the SQL Query. more details in the attached snippet Reproducible: Always Steps to Reproduce: 1. use the CriteriaBuilder 2. 3.
Created attachment 171409 [details] java code snippet describing the problem
I ran into the same bug, but combining isNull (or isNotNull) with equals. It considers the equals and ignores the isNull (or isNotNull). I described my experience with this bug here, if anyone is interested: http://stackoverflow.com/questions/3014313/jpa-2-criteria-api-why-is-isnull-being-ignored-when-in-conjunction-with-equal/3019159#3019159 In a comment to my post in that forum, another forum member said he tested with Hibernate Entity Manager 3.5.1 and it worked as expected.
Setting target and priority. See the following page for details of the meanings of these: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
This is basic functionality that I would expect to work. Has anything been done to fix this? Will the fix be included in the next "maintenance release"? (2.1.1 perhaps?)
2.1.1 is complete and will be shipped shortly. The fix for this issue is not included in that release. I encourage the community to keep voting for this bug as votes are one of our main criteria for choosing community submitted bugs for our patch releases.
I think the correction of this issue is very important and usefull for many usage. I've tried to fix it by commenting some optimization code in CriteriaBuilderImpl.and(). public Predicate and(Expression<Boolean> x, Expression<Boolean> y){ CompoundExpressionImpl xp = null; CompoundExpressionImpl yp = null; if (((InternalExpression)x).isExpression()){ xp = (CompoundExpressionImpl)this.isTrue(x); }else{ xp = (CompoundExpressionImpl)x; } if (((InternalExpression)y).isExpression()){ yp = (CompoundExpressionImpl)this.isTrue(y); }else{ yp = (CompoundExpressionImpl)y; } //TEST FIX //TODO Eclipselink Bug 316144 // if (yp.isPredicate() && yp.expressions.isEmpty()){ // if (yp.isNegated()){ // return yp; // }else{ // return xp; // } // } // if (xp.isPredicate() && xp.expressions.isEmpty()){ // if (xp.isNegated()){ // return xp; // }else{ // return yp; // } // } org.eclipse.persistence.expressions.Expression currentNode = xp.getCurrentNode().and(yp.getCurrentNode()); xp.setParentNode(currentNode); yp.setParentNode(currentNode); return new PredicateImpl(this.metamodel, currentNode, buildList(xp,yp), BooleanOperator.AND); } It's working in my simple tests. Do you agree with this fix ?
I took a look at your suggested fix. There is a usecase that will break with that fix. That case is an expression like this: cq.where(qb.and(qb.disjunction(), qb.conjunction())); In this case qb.disjunction() and qb.conjunction() are used to represent false and true. The code you have commented out is used to handle that case.
Is there a chance to get this bug fixed in 2.1.2?
I hope that too. I just wonder that you don't consider this bug as a critical bug, because it prevents certain _very simple_ kind of queries from executed correctly. I bet a lot of people are using IS (NOT) NULL with AND. Or does someone know a workaround for this?
(In reply to comment #9) > I hope that too. I just wonder that you don't consider this bug as a critical > bug, because it prevents certain _very simple_ kind of queries from executed > correctly. I bet a lot of people are using IS (NOT) NULL with AND. Or does > someone know a workaround for this? On the system I was developing when I ran into this bug the workaround was to use JPQL for that specific query. With JPQL it works fine for me. The first comment also mentions the "less-readable" notEqual() or equal() as a possible workaround too. Vítor Souza
2.1.2 is closed to check-ins as it will ship soon. With the current number of votes I would consider this bug a possibility, but not a guarantee for the next release. Community: Please continue to vote for this bug if you consider it important.
Add my vote ! This case is used in simple requests. This fix is very important for industrial
Targetting for 2.2.0 and taking ownership. 2.2.0 is current scheduled to be the first release after 2.1.2
Created attachment 182372 [details] Propsed fix
Created attachment 182384 [details] Updated Patch
Created attachment 182386 [details] Updated Patch
Created attachment 182388 [details] Updated Patch
Fixed the checks for disjunction and conjunction to check for a null CurrentNode intstead of empty expressions Reviewed by Chris Delahunt Added tests to JUnitCriteriaUnitTestSuite for AND and OR Tested with JPA LRG
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink