Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1.3
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Code:
public List<OrderTimeRegInfo> findAllEntries(Employee worker, wtm.server.data.model.Order prodOrder) {
Criteria criteria = getSession().createCriteria(getPersistentClass());
criteria.add(Restrictions.eq(WTRegister.ORDER, prodOrder));
criteria.setProjection(Projections.projectionList()
.add(Projections.sum(WTRegister.TIMEUSED), "sumoftime")
.add(Projections.groupProperty(WTRegister.PRODUCT), WTRegister.PRODUCT)
.add(Projections.groupProperty(WTRegister.OPERATION), WTRegister.OPERATION)
.add(Projections.property(WTRegister.ORDER),WTRegister.ORDER)
.add(Projections.property(WTRegister.EMPLOYEE), WTRegister.EMPLOYEE)
);
criteria.setResultTransformer(new AliasToBeanResultTransformer(OrderTimeRegInfo.class));
List<OrderTimeRegInfo> entries = (List<OrderTimeRegInfo>) criteria.list();
The generated SQL (show_sql=true):Code:
Hibernate: select sum(this_.TimeUsed) as y0_, this_.Product as y1_, this_.Operation as y2_, this_.prodOrder as y3_, this_.Employee as y4_ from wtmworktimereg this_ where y3_=? group by this_.Product, this_.Operation order by this_.TimeStart desc
09:50:45,656 ERROR JDBCExceptionReporter:72 - Unknown column 'y3_' in 'where clause'
There is a problem in Hibernate - when you try to output the groupped column and there is also a restriction on this column, it uses the alias in 'where clause': so it uses y3_ instead of this_.prodOrder, causing an JDBC error.
Is it an official bug oor this situation can be avoided?[/b]