wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 32

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
I agree. Here's the link: http://aspose.com/file-tools
subject: Query Criteria in Hibernate
Similar Threads
Criteria API on fields without mapping
dynamic named queries
HIbernate Criteria when fired on VIEW returs list with NULL values
how to see the query that hibernate generates?
Is this possible?