This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes adding or in criteria query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "adding or in criteria query" Watch "adding or in criteria query" New topic
Author

adding or in criteria query

Ankit Chandrawat
Ranch Hand

Joined: Jan 03, 2008
Posts: 87
Hi,

I want to write a criteria query in Hibernate using which i can select dates of a particular month for multiple years(four years in total).

For example I want it fetch the rows for whose date should be
between
(1st april 2011 and 1st May 2011) or the date should be between
(1st april 2010 and 1st May 2010) or the date should be between
(1st april 2009 and 1st May 2009) or the date should be between
(1st april 2008 and 1st May 2008)

TIA,
Ankit
Anantha Sharma
Ranch Hand

Joined: Sep 01, 2010
Posts: 43

Hi Ankit,

you can use the Restrictions class in hibernate to achive this....


Here is a sample.



hope this helps.
Ankit Chandrawat
Ranch Hand

Joined: Jan 03, 2008
Posts: 87
Hi Anantha,

It worked really well. You saved my day. Thanks a lot.

Thanks and Regards,
Ankit Chandrawat
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: adding or in criteria query
 
Similar Threads
af:selectOneChoice - setting default selected value other than the first in line
oracle date between
Get date List between two dates in mysql
How to convert descriptive dates into Java Date format
Restrictions Between for Date in Hibernate Criteria