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: subquery with limit does not work anymore in hibernate 3
PostPosted: Mon Jun 20, 2005 3:04 pm 
Newbie

Joined: Mon Jun 20, 2005 2:51 pm
Posts: 13
Location: Brasil
The following query worked fine with Hibernate 2.1. It has a subquery that uses limit. It does not work anymore in Hibernate 3. The error message is:
Quote:
org.hibernate.hql.ast.QuerySyntaxError: expecting CLOSE, found 'limit'


The code is:

Code:
StringBuffer sql = new StringBuffer("select count(*) from TrainingsLog as log where log.richtig = true and log.id in ( select log2.id from TrainingsLog as log2 where log2.user = :userId and log2.loId = :loId and log2.loTyp = :loTyp order by log2.datumAnlage desc limit :limit  ) ");
Session session = HibernateUtil.getSession();
Query query = session.createQuery(sql.toString())
   .setLong("userId", user.getId().longValue())
   .setLong("loId", loId.longValue())
   .setInteger("loTyp", typ)
   .setInteger("limit", anzahlLetztenAntworten);
Integer count = (Integer)query.uniqueResult();
return count.intValue();               

I would appreciate any pointers,
thanks,

Axel

_________________
Skype: 'axelberle'


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 3:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Where in the Hibernate documentation (or even in ANSI SQL), does it mention any "limit" keyword?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 4:49 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
The keyword LIMIT is neither implemented in Hibernate, nor an ANSI SQL standard.
Though you can limit your query using "setMaxResults()" and "setFirstResult()".

Code:
Query query = Session.createQuery(sql.toString());
query.setFirstResult(1);
query.setMaxResults(50);


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.