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 9001833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:29:21+00:00 2026-06-16T00:29:21+00:00

I have a project that I have to implement a lazy sort of search

  • 0

I have a project that I have to implement a lazy sort of search on database.

What I’d like to do is to use org.hibernate.criterion.Example but using ‘or’ condition for
each property.

For example, let’s say I have a class like below

public class Cat{
   private String name;
   private String breed;
   private Date birthDay;
/*getter and setter omitted*/
}

And I set all three of the fields with some value

Cat cat2Find = new Cat();
cat2Find.setName("Nabi");
cat2Find.setBreed("That hairless Egyptian cat");
cat2Find.setBirthDay( someDate );    //5th May 2005 for example

I want to find a cat
whose name is “Nabi”
or breed is “hairless Egyptian cat”
or whose birthday is 5th May 2005

I tried using org.hibernate.criterion.Example but show_sql showed me it used And condition for each fields.
I also tried using org.hibernate.criterion.Disjunction with LogicalExpression
but it was so cumbersome to iterate through all the fields.

I wonder if there is some class that works like criterion.Example but with and condition for
each fields or I can choose either ‘And’ or ‘OR’.

Thank you for your time : )

  • 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-16T00:29:22+00:00Added an answer on June 16, 2026 at 12:29 am
        // Use disjunction() or conjunction() if you need more than 2 expressions
    Disjunction aOrBOrC = Restrictions.disjunction(); // A or B or C
    aOrBOrC.add(Restrictions.eq("b", "a"));
    aOrBOrC.add(Restrictions.eq("b", "b"));
    aOrBOrC.add(Restrictions.eq("b", "c"));
    
    // Use Restrictions.and() / or() if you only have 2 expressions
    crit.add(Restrictions.and(Restrictions.eq("a", "abc"), aOrBOrC));
    

    this way u can make simple query with “AND”/”OR”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had implement the project that have to use QR Reader via Zxing Project.
I have a Java project that I'm trying to implement with a model-view-controller design.
I have a project that compiles and runs on my system but when I
My project that I've spent almost 40hrs on is almost complete, but I have
I would like to have an application/script that I could use to execute a
Here is the project that I have been given: Design and implement a set
If I have a project that contains similar classes and some may use the
I have four components in my large project that I'm working on... Existing JPA/Hibernate
I have a a number of UIViewControllers in my project that implement the UITableViewDataSource
I have a project here that connects to an in-production database and grabs tables

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.