well, in theory this is right.
but in fact SOMETIMES Hibernate 3.2 generates incorrect SQL query for mysql:
Code:
// get last N runs for the user
Criteria criteria = session.createCriteria(RunBean.class)
.add(Restrictions.eq("user", user))
.setFirstResult(0)
.setMaxResults(runsNumber);
List list = criteria.list();
Code:
org.hibernate.exception.SQLGrammarException: could not execute query
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.loader.Loader.doList(Loader.java:2148)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
org.hibernate.loader.Loader.list(Loader.java:2024)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1533)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
I see the generated SQL statement is not valid for MySQL ("select top ..." is not accepted):
Code:
select top ? this_.id as id9_6_, this_.start_date ...................where this_.icl_user_id=?