-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Conversion SQL natif vers HQL et Criteria
PostPosted: Wed Jan 28, 2009 4:41 am 
Beginner
Beginner

Joined: Sat Jan 05, 2008 7:33 am
Posts: 26
Bonjur a tous

J'ai une requete SQL "toute simple" que j'aimerais exprimer sous forme HQL ET
Criteria
Tout ce que j'ai pu essayer jusqu'a maintenant a ete infructueux et en faisant des recherches dans ces forum, ou sur google concernante les subqueries mais je n'ai rien trouve qui me permette d'aboutir a un code qui fonctionne si ce n'est en "native SQL query"

Est ce que quelqu'un peut m'aiguiller vers la solution
Par avance merci

Voici donc la "bete" qui retourne les deux derniers fichiers demo et test d'un repertoire donne en une seule operation

Code:
select db_id,shortname,fullname,file_date from
    (select db_id,shortname,fullname,file_date from Files
            where folder_id=1 and shortname in ('demo','test')
            order by shortname,file_date desc)
    as subquery
group by name


cela peut aussi s'ecrire comme suit:

Code:
select db_id,shortname,fullname,file_date from
    (select name as xname,max(file_date) as last from Files
             where folder_id=1 and name in ('demo','test')
            group by name)
    as subquery inner join Files as result
    where subquery.xname = result.shortname and subquery.last = result.file_date


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.