Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

"not in" expression is not working properly #127

Closed
mdpinar opened this Issue · 2 comments

3 participants

@mdpinar

There are 4 country code in db: UK, USA, TR, BR

//It is working properly
TypedQuery q = this.cq("select c from Country c where c.code in ('TR', 'UK')", Country.class);
Assert.assertEquals(2, q.getResultList().size());

//It is throwing an IllegalArgumentException with "Parameter with the name codeList does not exist"
q = this.cq("select c from Country c where c.code not in (:codeList)", Country.class).setParameter("codeList", codeList);
Assert.assertEquals(4, q.getResultList().size());

//Expected 3 but was 0
q = this.cq("select c from Country c where c.code not in ('TR')", Country.class);
Assert.assertEquals(3, q.getResultList().size());

@mdpinar mdpinar referenced this issue
Closed

not in tests #128

@iabughosh

I've tested it too, it seems that the reporter is right, i have the following code :

countries = em.createQuery("SELECT c FROM Country c where c.codeName in (:codeList)", Country.class).setParameter("codeList", params).getResultList();

logger.info("Result count with params query IN condition {}", countries.size());

countries.clear();

countries = em.createQuery("SELECT c FROM Country c where c.codeName not in (:codeList)", Country.class).setParameter("codeList", params).getResultList();

logger.info("Result count with params query NOT IN condition {}", countries.size());

first query works fine, second query throws exception :
java.lang.IllegalArgumentException: Parameter with the name codeList does not exist

@asimarslan
Owner

Quick work around for this bug is pulling the "not" infront of the variable

example;

SELECT c FROM Country c where c.codeName not in (:codeList)    

to

SELECT c FROM Country c where not ( c.codeNam in (:codeList) )
@asimarslan asimarslan referenced this issue
Merged

Issue 127 #131

@asimarslan asimarslan closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.