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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:59:37+00:00 2026-05-23T07:59:37+00:00

I am working on a project that is using hibernate. We have a database

  • 0

I am working on a project that is using hibernate.
We have a database and now I would like to query it.

In the ideal case, I know I am able to recover an object by its ID or by using Hibernate’s query language. But it would be optimal to me if there was a method to which I send an object with the attributes I want to be used as a filter and get back all the objects in that table that match these criterias.
For instance

Person p = new Person();
p.setName("Junior");
p.setAge(10);
session.Load(Person.class, p); //this would return all "junior" with age = 10

I imagine Hibernate would provide a similar functionality. Does it? Which method should I use?

Thanks,
Oscar

EDIT:
@nIKUNJ indicated me to Criteria, which would be something very similar to what I need.
The problem is: I would like to have a DatabaseManager class, which would handle the save, load, etc features.
For instance, my load would look like this:

public <T extends Serializable> List<T> load(T filters, Class<T> type)
{
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();

        List<T> searchResult;
        session.beginTransaction(); 

        searchResult = ((List<T>)session.get(type, filters)); //assuming the method
                                                 //I asked for in the question exists


        return searchResult;
}

This way, I would be able to send almost any object to this method and the method would query the database and return me a List of objects that match the criteria.

Do you have any idea how I could mimic this behavior that using the Criteria class?

Thanks,
Oscar

  • 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-23T07:59:37+00:00Added an answer on May 23, 2026 at 7:59 am

    I think Hibernate Criteria can help you.

    You can use one parameter class having three attributes: name, type and value. Name will be name of you column, type will be equals, less then, greater then etc. condition types, and value will be value for that condition.
    For example, name="person.age", type = greater equal, value=18. Create a utility method that converts these parameters into criteria objects.

    Now, create a method like this:

    public <T extends Serializable> List<T> load(List<Parameter> params, Class<T> type)
    {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    
            List<T> searchResult;
            session.beginTransaction(); 
            Criteria criteria = createCriteriaFromParams(params);    
            searchResult = criteria.list();  
    
            return searchResult;
    }  
    

    This is very simple scenario. You can create some complex criteria by adding some extra attributes in parameter list.

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

Sidebar

Related Questions

I'm working on a project that is considering using Cassandra as a database. We
I'm working on a java project full of Hibernate (3.3.1) mapping files that have
I have been working with a project which is using grails / hibernate with
I'm currently using Spring+Hibernate+MySQL for a project I'm working on. I realized that a
I am currently working on a project that is using Dojo as the js
I'm working on a project that is currently using the Zend Framework 1.7.6, however
i will be working on a project that tries to determine your position using
I am working on a Silverlight project that uses Django on the server using
I am working a project that does not have a trunk / branches /
I am working on a web project that is Spring+Hibernate+MySQL based. I am stuck

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.