This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Query Criteria in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Query Criteria in Hibernate" Watch "Query Criteria in Hibernate" New topic

Query Criteria in Hibernate

Mayur Shinde

Joined: Feb 15, 2012
Posts: 18

I am having multiple texbox for different parameters of a POJO and through this values I have to execute query. If all parameters are explicitly submitted by user then there is no problem in query, since all criteria are there.
If user din't fill up all textbox what will be the query for checking null values and then only allowing it to be a part of criteria. I am using hibernate as ORM Tool.

Mayur Shinde
Ganesh Shirsat
Ranch Hand

Joined: Jan 10, 2010
Posts: 33

Hi Mayur,

1. check how many parameter are exist.
2. According to parameter create different criterion object and add in DetachedCriteria.

You can use DetachedCriteria.

Step 1

Ste 2

Mayur Shinde

Joined: Feb 15, 2012
Posts: 18
Thanks Ganesh,

It solved my problem that how i will be creating my hibernate query(parameter which i will be passing). But now i am facing a new problem that i am having two class A & B, with relation one to many so A is having Set<A>, now i want to query db with the help of Set<A> like where Set<A>=?, So what will be query in hql.

Mayur Shinde
Consider Paul's rocket mass heater.
subject: Query Criteria in Hibernate
It's not a secret anymore!