-->
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: How to write select with LIMIT keyword using HQL?
PostPosted: Wed Sep 19, 2007 8:49 am 
Beginner
Beginner

Joined: Mon May 14, 2007 2:50 am
Posts: 22
Hibernate version:
1.2


Is it possible to write HQL to limit returned results?
For example, :
Code:
"from Role r LIMIT 10";


Or do i have to use something like:

Code:
Post post = (Post)session.CreateCriteria(typeof(Post))
     .Add(Expresion.Like("Title", title))
     .AddOrder(Order.Asc("PublishedAt"))
     .SetFirstResult(0)
     .SetMaxResult(1)
     .UniqueResult();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 10:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Code:
IQuery q = session.CreateQuery("from Role")
    .SetMaxResult(10);

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 10:56 am 
Beginner
Beginner

Joined: Mon May 14, 2007 2:50 am
Posts: 22
karlchu wrote:
Code:
IQuery q = session.CreateQuery("from Role")
    .SetMaxResult(10);


Ok, I got it:)
Limit is not supported in HQL

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 12, 2007 5:44 pm 
Newbie

Joined: Wed Dec 12, 2007 5:31 pm
Posts: 1
It would be nice to add this as a feature, to enable named queries to include the limit.


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.