Ok, so I'm using Criteria api now and I'm using it as below:
Criteria criteria =
this.sessionFactory.getCurrentSession().createCriteria(clazz);
criteria.addOrder(Order.asc(sortByProperty));
criteria.add(Restrictions.like(searchProperty, searchString,
MatchMode.ANYWHERE));
ProjectionList projList = Projections.projectionList();
for(String property: propertyList) {
projList.add(Projections.property(property), property);
}
criteria.setProjection(projList)
.setResultTransformer( Transformers.aliasToBean(classToRetrieve));
criteria.list();
...
propertyList is an ArrayList containing
propList.add("id");
propList.add("name");
This generates the sql as below with an exception:
Hibernate: select this_.ID as y0_, this_.NAME as y1_ from ADMIN.PRODUCTS this_ where y1_ like ? order by y1_ asc
2007-04-12 01:30:56,013 WARN [org.hibernate.util.JDBCExceptionReporter] - <SQL Error: 20000, SQLState: 42X04>
2007-04-12 01:30:56,013 ERROR [org.hibernate.util.JDBCExceptionReporter] - <Column 'Y1_' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'Y1_' is not a column in the target table.>
However, I tried the same approach without using Projections and transforms and I get the following sql with no errors.
Hibernate: select this_.ID as ID0_0_, this_.NAME as NAME0_0_, this_.PRICE as PRICE0_0_, this_.AMOUNT as AMOUNT0_0_ from ADMIN.PRODUCTS this_ where this_.NAME like ? order by this_.NAME asc
Size is = 1
Name=Jacket
Id=8a95d9c511e2c44e0111e2c456b30002
What am I doing incorrectly?
Thanks,
Roopa
|