• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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...
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic