4

I'm trying to exclude a bunch of results from a database SELECT using the "NOT IN" keywords, but the exclusion list is still being returned. Using JPQL (JPA2.0) my query looks like:

Query query = em.createQuery("SELECT foo.id FROM FooEntity fooEntity WHERE foo.id NOT IN ('" + exclusionList.toString() + "') ORDER BY foo.id").setFirstResult(startPosition).setMaxResults(numberOfAppsToReturn);

exclusionList is a StringBuffer. There is no error reported that I can see, but the id's in the exclusion list are still returned. Is there an alternative JPQL way of doing this?

Thanks in advance.

MeanwhileInHell
  • 6,780
  • 17
  • 57
  • 106

1 Answers1

6

I think the mistake is in foo. What is foo you have to defined it any where.

Write FooEntity foo instead of FooEntity fooEntity

Have a look on the following URL.

JPQL, How to NOT select something

Community
  • 1
  • 1
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
  • Hi Deepak, just discovered the problem was within my stringBuilder, I was surrounding the entire list with a single quote, rather than surrounding each item in the list with a single quote. Eg, ('item1,item2,item3...') instead of ('item1','item2','item3'...) I'll vote for your answer anyway to say thanks for responding. – MeanwhileInHell May 27 '11 at 14:22