-->
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: Trouble with LIMIT clause
PostPosted: Tue May 20, 2008 2:35 pm 
Newbie

Joined: Tue May 20, 2008 2:09 pm
Posts: 3
We have a working hibernate app in Tomcat.
It is using hibernate 3, MYSQL 5.0.41.

I added a limit clause to a working query and get an exception.

Here is my query:
FROM UserAuditEventLogs WHERE realmid=:orgName AND userid=:userName AND eventTime>=:startTime AND eventTime<=:endTime ORDER BY eventId LIMIT 1000

I also tried putting the LIMIT clause before the WHERE clause
and specifying both arguments explicitly (LIMIT 0,1000).

The limit clause works fine if I send the query directly to MySQL
through one of their clients (query browser or command line).

Any help is appreciated.

- Kurt

Here is the exception:

10:50:51,092 [org.hibernate.hql.PARSER] (http-8080-Processor23) ERROR: line 1:162: unexpected token: LIMIT
10:50:51,295 [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/SAAS].[action]] (http-8080-Processor23) ERROR: Servlet.service() for servlet action threw exception
java.lang.NoSuchMethodError: org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr/RecognitionException;Lantlr/collections/impl/BitSet;)V
at org.hibernate.hql.antlr.HqlBaseParser.identPrimary(HqlBaseParser.java:4049)
at org.hibernate.hql.antlr.HqlBaseParser.primaryExpression(HqlBaseParser.java:861)
at org.hibernate.hql.antlr.HqlBaseParser.atom(HqlBaseParser.java:3422)
at org.hibernate.hql.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:3200)
at org.hibernate.hql.antlr.HqlBaseParser.multiplyExpression(HqlBaseParser.java:3082)
at org.hibernate.hql.antlr.HqlBaseParser.additiveExpression(HqlBaseParser.java:2802)
at org.hibernate.hql.antlr.HqlBaseParser.concatenation(HqlBaseParser.java:570)
at org.hibernate.hql.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2586)
at org.hibernate.hql.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2449)
at org.hibernate.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2413)
at org.hibernate.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2331)
at org.hibernate.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2296)
at org.hibernate.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:2082)
at org.hibernate.hql.antlr.HqlBaseParser.orderElement(HqlBaseParser.java:2122)
at org.hibernate.hql.antlr.HqlBaseParser.orderByClause(HqlBaseParser.java:1248)
at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:751)
at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:296)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:159)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:238)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:155)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)

Java code:

public static List<UserAuditEventLogs> getAuditEvents(String orgName, String userName, Timestamp startTime, Timestamp endTime) {
Session sessionObj = HibernateSessionFactory.getSession();

// The result list
List<UserAuditEventLogs> lsResult = null;

try {
// Build the SQL query string
String strQuery = "FROM UserAuditEventLogs WHERE realmid=:orgName AND userid=:userName AND eventTime>=:startTime AND eventTime<=:endTime ORDER BY eventId LIMIT 1000";

// Create the hibernate query
Query hqlquery = (Query) sessionObj.createQuery(strQuery);

// Set the select parameters
hqlquery.setString("orgName", orgName);
hqlquery.setString("userName", userName);
hqlquery.setTimestamp("startTime", startTime);
hqlquery.setTimestamp("endTime", endTime);

// Create instance of the object representation of the table result
lsResult = (List<UserAuditEventLogs>)hqlquery.list();

} catch (HibernateException e) {
log.error("HibernateException: " + e.getMessage());
e.printStackTrace();
} finally {
// Close the session when done
sessionObj.close();
}
return lsResult;
}


Top
 Profile  
 
 Post subject: Found a workaround
PostPosted: Tue May 20, 2008 5:27 pm 
Newbie

Joined: Tue May 20, 2008 2:09 pm
Posts: 3
This poster had a similar problem:

http://forum.hibernate.org/viewtopic.php?t=986909

"I solved this by using createSQLQuery instead of createQuery. This doesn't do any translating."

The same solution worked for me.

- Kurt


Top
 Profile  
 
 Post subject: Another solution
PostPosted: Wed May 21, 2008 1:12 pm 
Newbie

Joined: Tue May 20, 2008 2:09 pm
Posts: 3
This is also supposed to work, but I haven't tried it yet:

hqlquery.setMaxResults(maxRecords);
hqlquery.setFetchSize(maxRecords);


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.