Hibernate version: v3.1.2
That piece of code was working with v2, but does not work anymore as I just migrated to v3.1.2. I have the following exception with the code below: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: limit near line 1, column 165 [select o from com.etil.sudetp.business.manager.offerbook.impl.OfferBookMarketOverview as o where o.homeFeatured=:feat AND o.productState=:prodState order by rand() limit 5]
StringBuffer rand = new StringBuffer();
if (random == true) {
rand.append(" order by rand() limit 5");
}
Query offerMarkets;
if (catId == Global.ROOT_PRODUCT_CATEGORY_ID) {
offerMarkets = t.session
.createQuery("select o from OfferBookMarketOverview as o where o.homeFeatured=:feat AND o.productState=:prodState"+ rand);
offerMarkets.setString("feat", Global.YES);
offerMarkets.setString("prodState", ProductState.TRADE_STATE);
}
for (Iterator it = offerMarkets.iterate(); it.hasNext();) {
OfferBookMarketOverview marketOverview = (OfferBookMarketOverview) it.next();
I have tried with setMaxResults(5), but I have another exception as well: org.hibernate.exception.SQLGrammarException: could not execute query using iterate.
What can I use then?
Any help will be very much appreciated.
Cheers.
DvJ
|