-->
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: select * wrapping sub select in HQL
PostPosted: Sun Jul 25, 2010 4:00 am 
Newbie

Joined: Mon Dec 25, 2006 4:59 am
Posts: 15
Hi guys

How can I use something like
Code:
select * from(...)
on sub select in HQL query ?

My motivation for it is that i need to use order by and limit the number (omitted at this point) of returned rows from inner select.
While the sorted and reduced rows will be part of "in" expression of wrapping query

In regular SQL with little help from Oracle row)number function it looks like this
Code:
   
select
   /* user fields */
from
    /* user table */
where
    userCondition.category in (
       select
          all.category,
          order by all.CREATED_DATE asc)
      from
          (
              select definition.category, CREATED_DATE
              from
                  Event
              where Event.typeId =  definition.typeId
                   Event.CREATED_DATE>=? and
                   Event.CREATED_DATE<=?
          )
      all       
      )


what i am trying to do is the following query,
while the "Event.definition.category.id from" line fails with Query syntax exception
Code:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token


Code:
select u
from User as u
join u.conditions as conditions
where conditions is not empty
and conditions.category.id in (
Event.definition.category.id  from (
    select op.definition.category.id from Event op
    where op.createdAt  >= :timeFrom  and op.createdAt  <= :timeTo
    order by op.createdAt
    )
  ) 


thx


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.