Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1145 connectés 

  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  [Hibernate SQL] Rownum et Order by

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Hibernate SQL] Rownum et Order by

n°1583334
Ryval
Posté le 06-07-2007 à 16:46:06  profilanswer
 

Bonjour,
 
j'essaye de recuperer les x premiers lignes d'une table.
 
La requete devrait donc être du style :  

Code :
  1. from ( select * from com.neuf.mvno.persistence.entites.CommandeMarc as cmd where cmd.statut = :statut and cmd.ligneTelephone.idInterneTelephone=:idLigneTelephone order by cmd.id DESC ) where rownum <= 1


 
Mais j'obtiens l'exception suivante à l'execution :
 
 

Code :
  1. org.springframework.orm.hibernate.HibernateQueryException: in expected: select [from ( select * com.neuf.mvno.persistence.entites.CommandeMarc as cmd where cmd.statut = :statut and cmd.ligneTelephone.idInterneTelephone=:idLigneTelephone order by cmd.id DESC ) where rownum <= 1]; nested exception is net.sf.hibernate.QueryException: in expected: select [from ( select * com.neuf.mvno.persistence.entites.CommandeMarc as cmd where cmd.statut = :statut and cmd.ligneTelephone.idInterneTelephone=:idLigneTelephone order by cmd.id DESC ) where rownum <= 1]
  2. net.sf.hibernate.QueryException: in expected: select [from ( select * com.neuf.mvno.persistence.entites.CommandeMarc as cmd where cmd.statut = :statut and cmd.ligneTelephone.idInterneTelephone=:idLigneTelephone order by cmd.id DESC ) where rownum <= 1]
  3. at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)
  4. at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
  5. at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
  6. at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
  7. at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
  8. at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
  9. at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
  10. at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1572)
  11. at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
  12. at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:49)


 
Je suis donc venu a testé la requete undirected sous SQuirreL et ca marche bien.
 
Ensuite j'ai  voulu testé la requete suivante :

Code :
  1. from com.neuf.mvno.persistence.entites.CommandeMarc as cmd where cmd.statut = :statut and cmd.ligneTelephone.idInterneTelephone=:idLigneTelephone and rownum <= 1 order by cmd.id DESC


 
Et à ma grande surprise, elle marche !!!!
J'ai appronfondi mes tests sous SQuirreL et conclusion : le rownum est valorisé APRES le group by !!!!
Y'a t-il eu une evolution ?? je suis sous oracle  9.2.0.6.0.
 

Code :
  1. select ROWNUM, id from Commande_Marc cmd where rownum <= 6 order by id DESC
  2. ===>
  3. 1 106
  4. 2 104
  5. 3 103
  6. 4 102
  7. 5 101
  8. 6 93


 

Code :
  1. select ROWNUM, id from Commande_Marc cmd where rownum <= 6
  2. ===>
  3. 1 2
  4. 2 3
  5. 3 4
  6. 4 5
  7. 5 6
  8. 6 7

mood
Publicité
Posté le 06-07-2007 à 16:46:06  profilanswer
 

n°1583513
moi23372
Posté le 07-07-2007 à 11:58:07  profilanswer
 

si c'est pour faire de l'hibernate et pondre toi même les query, il n'y a alors aucun interet d'utiliser un OR mapping comme hibernate.
 
De plus, si tu laisse faire hibernate, il va te faire cela comme un grand.
Il existe par ailleurs une options dans hibernate pour ne récupérer que les x premières lignes.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  [Hibernate SQL] Rownum et Order by

 

Sujets relatifs
Conversion DateTime en timeStamp avec contrainte SQL|SQL] Conversion Long en Chaine de caractère
[SQL Server 2005] Restauration d'une table dans une autre[RESOLU] Une liste de pays dans ma base de données SQL
[Oracle] Sous requête contenant un ORDER BY (pagination)[SQL server et ODBC] PB erreur 3151 aléatoire !
Une erreur SQL qui m'est inconnue[MYSQL] ORDER BY la plus petite de deux valeurs
[SQL] Probleme avec mon site et SQL ![SQL 2005] Problème pour une requête SELECT
Plus de sujets relatifs à : [Hibernate SQL] Rownum et Order by


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR