Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:41:49+00:00 2026-06-03T19:41:49+00:00

I set up method to query database using WHERE IN, but the query performs

  • 0

I set up method to query database using WHERE IN, but the query performs opposite of how I expect.

CriteriaBuilder qb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<ActivityLog> c = qb.createQuery(ActivityLog.class);
Root<ActivityLog> p = c.from( ActivityLog.class );
Predicate condition1 = qb.equal( p.get(ActivityLog_.div), div);

Collection<String> viewStatus = new ArrayList<String>();
viewStatus.add("C");
viewStatus.add("U");
viewStatus.add("D");
Predicate condition2 = qb.equal(p.get(ActivityLog_.status), p.get(ActivityLog_.status).in(viewStatus));

c.where( qb.and(condition1, condition2) );
c.orderBy( qb.desc( p.get( ActivityLog_.update_time.getName() ) ) );

TypedQuery<ActivityLog> q = getEntityManager().createQuery(c); 
q.setMaxResults(15);

return q.getResultList();

The results are actually the opposite — I get STATUS the are NOT C,U,D.
If I change the Predicate condition2 line — I get the results that I expect??

Predicate condition2 = qb.notEqual(p.get(ActivityLog_.status), p.get(ActivityLog_.status).in(viewStatus));

Is there a bug with MySQL driver or Eclipselink? or a flaw in my thinking?

My hope is to retrieve from ActiivtyLog where divsion = div and status
IN (C,U,D)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:41:50+00:00Added an answer on June 3, 2026 at 7:41 pm

    Why are you using qb.equal(p.get(ActivityLog_.status), yourInCondition)? The in condition should return a true or false, so i don’t see why you would want to check that it equals your status.
    In EclipseLink you can turn Logging to Fine or Finest to see the SQL that gets generated, which makes it easier to tell how your queries might be going wrong.

    What I think you might want instead is just

    Predicate condition2 = p.get(ActivityLog_.status).in(viewStatus)) 
    

    which can also be done as :

    In<String> in = qb.in( p.get(ActivityLog_.status) );
    in.value("C").value("U").value("D");
    c.where( qb.and(condition1, in) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the CriteriaBuilder and CriteriaQuery to build my query to the database,
I ran this sql query in my database: update payments set method = 'paysafecard'
I used setCursor() method to set a cursor for JTable. But that cursor is
I'm using System.Data.SQLite to query a database with c#/linq . The rows I want
I'm trying to respond to a get request in java using a database. But
I'm trying to search an LDAP database using the ODQuery method. I have the
I am using the groovy.sql.Sql class to query a database and process the results.
I have a method set up that uses jquery form for a file upload
How to set compression method for SSL/TLS connection created with M2Crypto and TwistedProtocolWrapper
I want to create a method ( set ) that injects arguments into another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.