Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query Criteria in Hibernate

 
Mayur Shinde
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Regards,
Mayur Shinde
 
Ganesh Shirsat
Ranch Hand
Posts: 33
Google Web Toolkit Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
Mayur Shinde
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic