Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

"not in" expression is not working properly #127

Closed
mdpinar opened this Issue Dec 25, 2012 · 2 comments

Comments

Projects
None yet
3 participants
Contributor

mdpinar commented Dec 25, 2012

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 Dec 25, 2012

Closed

not in tests #128

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

Owner

asimarslan commented Dec 26, 2012

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 Jan 11, 2013

Merged

Issue 127 #131

@asimarslan asimarslan closed this Jan 16, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment