-->
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.  [ 6 posts ] 
Author Message
 Post subject: Bug with LIMIT and new parser in Hibernate3 final?
PostPosted: Fri Apr 01, 2005 3:53 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
I just tried to switch from Hibernate 3.0 RC1 using the classic parser to Hibernate 3.0 final with the new parser. I haven't used the new parser yet because of a problem with correlated subqueries, which is now supposed to be fixed.

I recognized that my code, which works just fine with the classic parser (Hibernate 3 RC1 and final), doesn't work using the new parser. Find the code, the SQL output and the exception below.

Thanks for your help!

Best regards
Sven



Hibernate version: 3.0 final

Name and version of the database you are using: MySQL 4.0.24


code
Code:
final StringBuffer buffer = new StringBuffer(300)
      .append("SELECT order FROM Order AS order WHERE ")
      .append("order.aNode LIKE :aNode AND ")
      .append("order.customer LIKE :customer AND ")
      .append("order.orderName LIKE :orderName AND ")
      .append("order.responsiblePersonExternal LIKE :rpext AND ")
      .append("order.responsiblePersonInternal LIKE :rpint ")
      .append("ORDER BY order.aNode DESC ")
      .append("LIMIT 0, :maxResultCount");

final Session session = HibernateUtil.getSession();
final Query query = session.createQuery(buffer.toString());
query.setString("aNode", "%" + aNode + "%");
query.setString("orderName", "%" + orderName + "%");
query.setString("customer", "%" + customer + "%");
query.setString("rpint", "%" + rpInt + "%");
query.setString("rpext", "%" + rpExt + "%");
query.setInteger("maxResultCount", maxResultCount + 1);
final List result = query.list();



output using the classic parser
Code:
Hibernate: select order0_.id as id, order0_.anode as anode0_, order0_.ordername as ordername0_, order0_.customer as customer0_, order0_.rpe as rpe0_, order0_.rpi as rpi0_ from aorder order0_ where (order0_.anode LIKE ? )AND(order0_.customer LIKE ? )AND(order0_.ordername LIKE ? )AND(order0_.rpe LIKE ? )AND(order0_.rpi LIKE ? ) order by  order0_.anode DESC LIMIT 0 , ?



exception using the new parser
Code:
org.hibernate.QueryException: Named parameter does not appear in Query: maxResultCount [SELECT order FROM de.company.project.persistence.Order AS order WHERE order.aNode LIKE :aNode AND order.customer LIKE :customer AND order.orderName LIKE :orderName AND order.responsiblePersonExternal LIKE :rpext AND order.responsiblePersonInternal LIKE :rpint ORDER BY order.aNode DESC LIMIT 0, :maxResultCount]



output using the new parser
Code:
Hibernate: select order0_.id as id, order0_.anode as anode0_, order0_.ordername as ordername0_, order0_.customer as customer0_, order0_.rpe as rpe0_, order0_.rpi as rpi0_ from aorder order0_ where ((order0_.anode like ?) and (order0_.customer like ?) and (order0_.ordername like ?) and (order0_.rpe like ?) and (order0_.rpi like ?)) order by  order0_.anode DESC


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 01, 2005 9:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and the error is ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 01, 2005 9:36 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
See the part "exception using the new parser" in my posting.

exception using the new parser
Code:
org.hibernate.QueryException: Named parameter does not appear in Query: maxResultCount [SELECT order FROM de.company.project.persistence.Order AS order WHERE order.aNode LIKE :aNode AND order.customer LIKE :customer AND order.orderName LIKE :orderName AND order.responsiblePersonExternal LIKE :rpext AND order.responsiblePersonInternal LIKE :rpint ORDER BY order.aNode DESC LIMIT 0, :maxResultCount]



It says that the "Named parameter does not appear in Query" which is mentioned in the LIMIT part of the query. This part seems to be not considered by the new parser.

Sven


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 01, 2005 9:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hql dont have a limit keyword!

use setFirstResult and setMaxResult.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 01, 2005 10:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
This is actually related to http://opensource.atlassian.com/projects/hibernate/browse/HHH-164
My guess is that if you enabled debug logging for org.hibernate.hql.AST you'll see that in the resulting AST the LIMIT node is just not there, meaning it silently cuts off everything after that.

Max is right. The parser should throw an exception because LIMIT is not recognized.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 03, 2005 3:19 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
OK, thanks a lot for this information.
I just wondered why it worked with the classic parser.

I will use setFirstResult and setMaxResult.

Best regards
Sven


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