-->
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: Limit clause problem with MySQL
PostPosted: Tue Mar 01, 2005 5:20 am 
Newbie

Joined: Tue Mar 01, 2005 5:11 am
Posts: 2
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():
Configuration config = new Configuration();
config.setProperties(props);
config.addFile("employee.hbm.xml");
SessionFactory sessFact = config.buildSessionFactory();
Session session = sessFact.openSession();

String queryStr = "from employee employee where employee.age = ? and employee.name like ?";
List values = new Vector();
values.add("26");
values.add("ja%");

Transaction tx = null;
try {
tx = session.beginTransaction();
Query query = session.createQuery(queryStr);
if (values != null) {
for (int i = 0; i < values.size(); i++) {
query.setParameter(i, values.get(i));
}
}
System.out.println("The query string "+query.getQueryString());

query.setFirstResult(0);
query.setMaxResults(10);

List myList = query.list();
System.out.println("The list "+myList);
for (int i = 0; i < myList.size(); i++) {
Object obj = myList.get(i);
System.out.println("The object "+obj + " "+obj.getClass());
}
tx.commit();
return myList;
}
catch (Exception ee) {
if (tx!=null) tx.rollback();
ee.printStackTrace();
}
finally {
session.close();
}


Full stack trace of any exception that occurs:
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1424)
at org.hibernate.loader.Loader.list(Loader.java:1404)
at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:876)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:833)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.jkl.runtime.ruleengine.persistence.Connection.getTable(Connection.java:91)
at com.jkl.runtime.ruleengine.persistence.Connection.getTable(Connection.java:54)
at com.jkl.runtime.ruleengine.persistence.Connection.main(Connection.java:129)
Caused by: java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?, ?' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1534)
at com.mysql.jdbc.ServerPreparedStatement.serverPrepare(ServerPreparedStatement.java:1489)
at com.mysql.jdbc.ServerPreparedStatement.<init>(ServerPreparedStatement.java:153)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1309)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1281)
at com.p6spy.engine.spy.P6Connection.prepareStatement(P6Connection.java:170)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:356)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:307)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:86)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1069)
at org.hibernate.loader.Loader.doQuery(Loader.java:356)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:199)
at org.hibernate.loader.Loader.doList(Loader.java:1421)
... 7 more


Name and version of the database you are using:
MySQL - 4.1.9


The generated SQL (show_sql=true):
Hibernate: select employee0_.ID as ID, employee0_.NAME as NAME0_, employee0_.AGE as AGE0_, employee0_.DEPARTMENT as DEPARTMENT0_, employee0_.SALARY as SALARY0_ from employee employee0_ where (employee0_.AGE=? )and(employee0_.NAME like ? ) limit ?, ?


Debug level Hibernate log excerpt:

Can U clarify where I am going wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 9:58 am 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
It seems be the problem as here:
http://forum.hibernate.org/viewtopic.php?p=2230718

_________________
Vincent


Top
 Profile  
 
 Post subject: Thanks.
PostPosted: Tue Mar 01, 2005 10:15 am 
Newbie

Joined: Tue Mar 01, 2005 5:11 am
Posts: 2
Thanks Vincent, really appreciate your effort


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