Bonjour,
j'essaye de recuperer les x premiers lignes d'une table.
La requete devrait donc être du style :
Code :
- 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 :
- 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]
- 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]
- at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)
- at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
- at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
- at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
- at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
- at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
- at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
- at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1572)
- at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
- 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 :
- 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 :
- select ROWNUM, id from Commande_Marc cmd where rownum <= 6 order by id DESC
- ===>
- 1 106
- 2 104
- 3 103
- 4 102
- 5 101
- 6 93
|
Code :
- select ROWNUM, id from Commande_Marc cmd where rownum <= 6
- ===>
- 1 2
- 2 3
- 3 4
- 4 5
- 5 6
- 6 7
|