-->
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: Query not correctly generated when using setMaxResults
PostPosted: Thu Jun 04, 2009 8:53 am 
Newbie

Joined: Thu Jun 04, 2009 8:49 am
Posts: 1
Hi all,

This is my first post in this forum and i hope this is the right place to do it.
I've been searching all over the web, but i couldn't find anything significantly similar to my problem.

This is the peace of code that i'm using to submit the query:

Code:
public List<BlogEntryExtended> findExtendedBlogEntries( int max )
throws SystemException
{
  try
    {
       Session session = getHibernateTemplate().getSessionFactory().openSession();
       Query query = session.getNamedQuery( "selectFeaturedEntries" );
       query.setMaxResults( max );
       List<BlogEntryExtended> list = (List<BlogEntryExtended>)query.list();
    }
    catch
    {
      // log exception.
    }
    finally
    {
      session.close();
    }
}


Here is the query:
Code:
FROM BlogEntryExtended bee
WHERE bee.blogsEntry.draft = false
AND bee.featured = true
ORDER BY bee.blogsEntry.displayDate DESC


And here is the main error:

Code:
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL serve
r version for the right syntax to use near '3 blogentrye0_.entryId as entryId1_, blogentrye0_.thumbnail as thumbnail1_, blog' at line 1


The problem seems to be on the number "3" at the beginning of the query. This is the value for the method parameter variable "max" in this execution.
According to what i have read, the query should be generated with a "LIMIT" keyword to "cut" the resultset.

Just to let you know, i'm using MySQL 5.1, tomcat 6.0.18, and hibernate 3.2.6

Thanks for your help.


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.