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.