具有预测的休眠标准

时间:2014-11-21 13:44:54

标签: java hibernate

尝试Criteria.Restriction使用Projections查询ProjectionList projections = Projections.projectionList().add(Projections.property("mId").as("mId")); projections.add(Projections.property("mDate").as("mDate")); Criteria criteria = mSession.createCriteria(MailAgroseguro.class) .add(Restrictions.between("mDate", dateMin, dateMax)) .setProjection(projections) .setResultTransformer(new AliasToBeanNestedResultTransformer(ObjectClass.class)); listObjectClass = (List<ObjectClass>)criteria.list();

我的代码是:

ObjectClass.java

编辑: public class ObjectClass { private Integer mId; private String mDate; }

Hibernate: select this_.mId as y0_, this_.mDate as y1_ from objectclass this_ where y1_ between ? and ?
[INFO] 2014-11-21 16:59:24,554 - org.hibernate.util.JDBCExceptionReporter -25221 [JavaFX Application Thread] WARN  org.hibernate.util.JDBCExceptionReporter  - SQL Error: 1054, SQLState: 42S22
[INFO] 2014-11-21 16:59:24,554 - org.hibernate.util.JDBCExceptionReporter -25221 [JavaFX Application Thread] ERROR org.hibernate.util.JDBCExceptionReporter  - Unknown column 'y1_' in 'where clause'

错误是:

Restriction

如果我没有添加Projections或{{1}}正常工作!

Edited2:已更新错误

感谢大家!

0 个答案:

没有答案