• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

HQL and criteria

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 43
Android Hibernate jQuery
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic