Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HQL and criteria

 
Alex Armenteros
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
Android Hibernate jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can use Restrictions & Projections to acheive it. You can find example on Page 289 of Hibernate Reference Document 3.6.0...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic