-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL query how to
PostPosted: Fri Sep 26, 2008 5:01 am 
Newbie

Joined: Mon Sep 01, 2008 3:41 am
Posts: 19
Hi all,

Since now, I only execute simple querys but how can translate this query from SQL to HQL?

SQL
Code:
SELECT
     *
FROM
   (select
         ROWNUM AS NUMERO,
         CI.RECAB_AREA,
         CI.RECAB_CLAVE,
         CI.RECAB_DESCORTA,
         CI.RECAB_DESLARGA,
         CI.RECAB_DISPONIBLEDESDE,
         CI.RECAB_DISPONIBLEHASTA,
         CI.RECAB_EMGRABA,
         CI.RECAB_EMMODIFICA,
         CI.RECAB_FEGRABA,
         CI.RECAB_FEMODIFICA,      
         CI.RECAB_IDREPORTCABECERA,
         CI.RECAB_NOMBERUTA
from REPORTCABECERA ci
where (ci.RECAB_DISPONIBLEHASTA >= SYSDATE
or ci.RECAB_DISPONIBLEHASTA is null)
order by ci.RECAB_AREA,
ci.RECAB_FEGRABA,
ci.RECAB_CLAVE) RC
WHERE RC.NUMERO BETWEEN (20*(1-1))+1 AND 20 * 1


My HQL
Code:
"SELECT "
             + "         RC.area, "
             + "         RC.nombre, "
             + "         RC.descripcionCorta, "
             + "         RC.descripcionLarga, "
             + "         RC.fechaIni, "
             + "         RC.fechaFin, "
             + "         RC.empleadoGrabacion, "
             + "         RC.empleadoModificacion, "
             + "         RC.fechaGrabacion, "
             + "         RC.fechaModificacion,       "
             + "         RC.id, "
             + "         RC.nombreRuta "
             + "FROM "
             + "   (select "
             + "         ROWNUM AS NUMERO, "
             + "         ci.area, "
             + "         ci.nombre, "
             + "         ci.descripcionCorta, "
             + "         ci.descripcionLarga, "
             + "         ci.fechaIni, "
             + "         ci.fechaFin, "
             + "         ci.empleadoGrabacion, "
             + "         ci.empleadoModificacion, "
             + "         ci.fechaGrabacion, "
             + "         ci.fechaModificacion,       "
             + "         ci.id, "
             + "         ci.nombreRuta "
             + " from CabeceraInforme ci "
             + " where (ci.fechaFin >= SYSDATE "
             + " or ci.FechaFin is null) "
             + " order by ci.area, "
             + " ci.fechaGrabacion, "
             + " ci.nombre) RC "
             + "WHERE RC.NUMERO BETWEEN (?1*(?2-1))+1 AND ?1 * ?2 ",numeroPaginas,paginaActual


The error
Code:
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 425 [SELECT          RC.area,          RC.nombre,          RC.descripcionCorta,          RC.descripcionLarga,          RC.fechaIni,          RC.fechaFin,          RC.empleadoGrabacion,          RC.empleadoModificacion,          RC.fechaGrabacion,          RC.fechaModificacion,                RC.id,          RC.nombreRuta FROM    (select          ROWNUM AS NUMERO,          ci.area,          ci.nombre,          ci.descripcionCorta,          ci.descripcionLarga,          ci.fechaIni,          ci.fechaFin,          ci.empleadoGrabacion,          ci.empleadoModificacion,          ci.fechaGrabacion,          ci.fechaModificacion,                ci.id,          ci.nombreRuta  from com.uw.diode.entity.CabeceraInforme ci  where (ci.fechaFin >= SYSDATE  or ci.FechaFin is null)  order by ci.area,  ci.fechaGrabacion,  ci.nombre) RC WHERE RC.NUMERO BETWEEN (?1*(?2-1))+1 AND ?1 * ?2 ]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 425 [SELECT          RC.area,          RC.nombre,          RC.descripcionCorta,          RC.descripcionLarga,          RC.fechaIni,          RC.fechaFin,          RC.empleadoGrabacion,          RC.empleadoModificacion,          RC.fechaGrabacion,          RC.fechaModificacion,                RC.id,          RC.nombreRuta FROM    (select          ROWNUM AS NUMERO,          ci.area,          ci.nombre,          ci.descripcionCorta,          ci.descripcionLarga,          ci.fechaIni,          ci.fechaFin,          ci.empleadoGrabacion,          ci.empleadoModificacion,          ci.fechaGrabacion,          ci.fechaModificacion,                ci.id,          ci.nombreRuta  from com.uw.diode.entity.CabeceraInforme ci  where (ci.fechaFin >= SYSDATE  or ci.FechaFin is null)  order by ci.area,  ci.fechaGrabacion,  ci.nombre) RC WHERE RC.NUMERO BETWEEN (?1*(?2-1))+1 AND ?1 * ?2 ]


I can't find a good HQL manual. Could you suggest someone to me?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 26, 2008 10:12 am 
Beginner
Beginner

Joined: Wed Sep 24, 2008 5:44 pm
Posts: 34
The Hibernate documentation is pretty good
http://www.hibernate.org/hib_docs/refer ... eries.html


Top
 Profile  
 
 Post subject: subquerys
PostPosted: Mon Sep 29, 2008 5:13 am 
Newbie

Joined: Mon Sep 01, 2008 3:41 am
Posts: 19
I have seen that Hibernate can use subquerys in the from clause but I need to execute this SQL query in HQL:

Code:
SELECT * FROM (
   SELECT ROWNUM N_ROW2, N_ROW FROM(
      SELECT ROWNUM N_ROW, CI.RECAB_IDREPORTCABECERA
      from REPORTCABECERA ci
      where (ci.RECAB_DISPONIBLEHASTA >= SYSDATE
      or ci.RECAB_DISPONIBLEHASTA is null)
      order by ci.RECAB_AREA,
      ci.RECAB_FEGRABA,
      ci.RECAB_CLAVE))
WHERE N_ROW2 BETWEEN 1 AND 15


How can I do it?

Thanks,

Praedos


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

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.