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

  • SEARCH
  • Home
  • 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 8479467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:02:02+00:00 2026-06-10T19:02:02+00:00

Say I have CustomerQueryInfo bean with the following properties: String firstName String lastName StatusEnum

  • 0

Say I have CustomerQueryInfo bean with the following properties:

  • String firstName
  • String lastName
  • StatusEnum status

I want to perform a “QueryDSL” search using this an object of this type that will return a list of customers List<Customer>.

If one of the fields of CustomerQueryInfo is null, I don’t want to use it in the search. Thus a CustomerQueryInfo object with all three fields set to null will return all customers.

I am looking for best practices to perform such a search with QueryDSL.

Is something like this OK:

private BooleanExpression isFirstNameLike(String firstName){
    if(firstName==null)
        return true BooleanExpression somehow;
    return QCustomer.customer.firstName.like(firstName);
}

private BooleanExpression isStatutEq(StatusEnum status){
    if(status==null)
        return true BooleanExpression somehow;
    return QCustomer.customer.status.eq(status);
}

then:

return query.from(customer).where(isFirstNameLike(customerQueryInfo.getFirstName).and(isLastNameLike(customerQueryInfo.getLastName).and(isStatusEq(customerQueryInfo.getStatus))).list;
  1. How do I return a BooleanExpression that evaluates to true?
  2. If the above approach is not advisable, then what is the recommended best practice?
  • 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-10T19:02:03+00:00Added an answer on June 10, 2026 at 7:02 pm

    You can safely use null predicates like this

    private BooleanExpression isFirstNameLike(String firstName){
        return firstName != null ? customer.firstName.like(firstName) : null;        
    }
    
    private BooleanExpression isStatusEq(StatusEnum status){
        return status != null ? customer.status.eq(status) : null;
    }
    

    And use the varargs aspect of where

    query.from(customer)
         .where(
             isFirstNameLike(customerQueryInfo.getFirstName()),
             isLastNameLike(customerQueryInfo.getLastName()),
             isStatusEq(customerQueryInfo.getStatus()))
         .list(customer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

say I have input data like so: firstName | lastName | Country Bob |
Let's say have a string... String myString = my*big*string*needs*parsing; All I want is to
Say I have a Telerik MVC Grid, AJAX bound and I want to put
Say i have a few fields like the following: abd738927 jaksm234234 hfk342 ndma0834 jon99322
Say I have the following template function: template <class T> void apply(const vector<complex<T> >&
Say I have a byte array with 100,000 bytes in it. I want to
Say I have the following code: private Integer number; private final Object numberLock =
Say have a linear model LM that I want a qq plot of the
Say I have an System.String[] type object. I can query the type object to
Say have the following code: public void SaveOrUpdate(OrderContract orderContract) { foreach (var orderContract in

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.