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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:41:25+00:00 2026-05-16T07:41:25+00:00

I have a model that has several properties. The properties can be primitive (String)

  • 0

I have a model that has several properties. The properties can be primitive (String) or complex (Object). The user can make a query on each primitive property. I would like to know if there is an easy way to build dynamically the query. I use Java and Hibernate.

The model

public class Model {
  String prop1;
  Point prop2;
  List<Shape> prop3;
}

Point and Shape are object that can contains primitives or objects. An example of a query would be all instances where prop1 = “A” and the coordinates are x = 3 and y = 8 and one of the shape is a circle.

prop1 = “A” and prop2.x = 3 and prop2.y and prop3.get(i).type = “Circle”; we would have to iterate on all instances of prop3.

My first idea was unmaintainable and inefficient. It consists in doing queries on all the primitive properties and then merge the results.

  • Get all instances where prop1 = “A”
  • Get all instances where prop2.x = 3
    and prop3 = y;
  • Get all instances where one of the
    Shape.type = “Circle”;
  • Get the intersection of all 3 sets

Is there any existing library or algorithm that can solve this problem in a better (smarter) way?

Thanks

  • 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-05-16T07:41:25+00:00Added an answer on May 16, 2026 at 7:41 am

    Have you looked at Criteria queries? It’s a Hibernate feature for constructing queries and parameters programmatically.

    If your intent is to query for entities that match all of these conditions:

    prop1 = “A” and prop2.x = 3 and prop2.y and prop3.get(i).type = “Circle”

    with support for association queries, then you could do something like

    Criteria criteria = session.createCriteria(Model.class);
    criteria.add(Restrictions.eq("prop1", "A"));
    criteria.createCriteria("prop2")
        .add(Restrictions.eq("x", 3));
        .add(Restrictions.eq("y", 2));
    criteria.createCriteria("prop3").add(Restrictions.in("type", "Circle"));
    
    List results = criteria.list();
    

    The real strength in Criteria queries is building the query in code rather than in a HQL string – allows you to dynamically add/set properties, etc.

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

Sidebar

Related Questions

I have a Model that has several properties. When I submit a form, I
I have a view with a model that has several fields. When I render
I have a model that has a ForeignKey to the built-in user model in
I have a User model that has many posts. Im trying to render the
I have a User model that has the following default_scope: default_scope where(account_id: Account.current_account.id) If
I have a ReactiveUI-like view model. It has several properties of different types which
I have a model (and model form based on it) that has several time
I have db.Model which has several properties as described below: class Doc(db.Model): docTitle =
I have a model, Foo . It has several database properties, and several properties
I have a mvvm(model view viewmodel) silverlight application that has several views that need

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.