-->
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.  [ 4 posts ] 
Author Message
 Post subject: Translate query
PostPosted: Fri Nov 05, 2010 7:42 am 
Newbie

Joined: Fri Nov 05, 2010 5:42 am
Posts: 3
Hello,
How do I translate this query in hibernate?
Maybe using Criteria or Query?

Code:
SELECT *
    FROM T_PROVINCIA A
    WHERE
         A.IDE_REG IN (1,2,3,4)   AND
         A.IDE_PRV IN (SELECT B.IDE_PRV FROM T_PROVINCIA B
                                WHERE A.IDE_REG = B.IDE_REG AND ROWNUM <= 3)
     ORDER BY A.IDE_REG, A.IDE_PRV


I should select a maximum of 3 provinces from each region in input.

Thanks


Top
 Profile  
 
 Post subject: Re: Translate query
PostPosted: Fri Nov 05, 2010 11:14 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
Just write HQL that does the same thing. What is the problem you need to help at?


Top
 Profile  
 
 Post subject: Re: Translate query
PostPosted: Fri Nov 05, 2010 11:21 am 
Newbie

Joined: Fri Nov 05, 2010 5:42 am
Posts: 3
r wrote:
Just write HQL that does the same thing. What is the problem you need to help at?


I wanted to apply the Criteria.

However, in HQL, I can not write "rownum <= 3".

Thanks


Top
 Profile  
 
 Post subject: Re: Translate query
PostPosted: Fri Nov 05, 2010 11:27 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
You can write something like following in HQL:

Code:
from Region region where region.id in (1,2,3,4) and size(region.provinces) <= 3


I hate Criteria, so I won't be able to help with them to you :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.