Bug 374657 - CriteriaBuilder - and(and(), or()) behaves as true
Summary: CriteriaBuilder - and(and(), or()) behaves as true
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 major with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-19 10:30 EDT by Marek Handl CLA
Modified: 2022-06-09 10:27 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Handl CLA 2012-03-19 10:30:38 EDT
Build Identifier: 2.3.0

CriteriaBuilder.and() method gives wrong results for certain parameters.

----------------------------------------------------
Code snippet:

CriteriaBuilder cb = this.em.getCriteriaBuilder();
CriteriaQuery<MyEntity> query = cb.createQuery(MyEntity.class);

query.where(cb.and(cb.and(), cb.or()));

TypedQuery<MyEntity> typedQuery = this.em.createQuery(query);
typedQuery.getResultList();

----------------------------------------------------
Generated SQL:

SELECT ID FROM MYENTITY

----------------------------------------------------

The SQL shows that the where clause has been evaluated as 'true', which is wrong.

However, when order of parameters is changed, it starts to work as expected. I.e. query.where(cb.and(cb.or(), cb.and())) results in a correct SQL query containing "WHERE 1=0".

The same applies when disjunction() is used instead of or(). 

Reproducible: Always
Comment 1 Marek Handl CLA 2012-03-19 11:18:10 EDT
Tested with the same result on version Eclipse Persistence Services - 2.3.2.v20111125-r10461
Comment 2 Tom Ware CLA 2012-04-16 09:44:06 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 3 Tomasz Bartczak CLA 2013-12-18 04:17:29 EST
This got fixed in 2.5.1

You can have an example running test case:

https://github.com/kretes/eclipseLinkPlayground/blob/master/src/test/java/some/NotAndPredicateTest.java

when using eclipselink 2.5.1 it worked. with previous - not.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:27:28 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink