GeeCON Prague 2014*
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


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "HQL and criteria" Watch "HQL and criteria" New topic
Author

HQL and criteria

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 73
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

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-expressions

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
Greenhorn

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...
 
wood burning stoves
 
subject: HQL and criteria