This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes HQL and criteria Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "HQL and criteria" Watch "HQL and criteria" New topic

HQL and criteria

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 75
I need to implement a query like this...

select count(*) as res from table where field1 in (...) and field2 in (...) and field3 in (...) and (time1-time2)<10;

That time1-time2 I know how to do it in HQL.

I there anyway to put these Criteria and HQL things together? I already know of sqlRestriction but I want to make the query compliant with Oracle and MySQL at the same time.

and I don't want to do it in HQL enterely
Anantha Sharma
Ranch Hand

Joined: Sep 01, 2010
Posts: 43

these are all the functions that hql is bundled with

hql translates these into meaningful sql functions based on the dialect.

now, there are many scenarios where a database vendor (like oracle) would have created different functions which are not a part of the hql's expression, in those cases, you'd have to use the SQL function name directly in the HQL (jut like you created an SqlRestriction..

if you want to ensure that you don't use any db vendor specific functions you can always load data & work with it afterwards.. or you can create a database view & do all the activities there....
Jacky S Zhang

Joined: Jul 21, 2010
Posts: 13
I think you can use Restrictions & Projections to acheive it. You can find example on Page 289 of Hibernate Reference Document 3.6.0...
I agree. Here's the link:
subject: HQL and criteria
It's not a secret anymore!