我使用分离式搜索,但必须使用分组依据。我的代码在下面:
@Transactional(propagation = Propagation.REQUIRED)
@Override
public List<Dossier> rechercher(DossierBean critere)
throws TechnicalException {
DetachedCriteria criteria = DetachedCriteria.forClass(Dossier.class);
criteria.add(Restrictions.eq("firstName", critere.getFirstName()));
criteria.add(Restrictions.eq("secondName", critere.getSecondName()));
criteria.add((Criterion) Projections.groupProperty("iddossier"));
List<Dossier> dList = findByCriteria(criteria);
return dList;
}
我得到这个例外:
Caused by: java.lang.ClassCastException: org.hibernate.criterion.PropertyProjection cannot
be cast to org.hibernate.criterion.Criterion
我知道是
groupProperty(...)
的问题,但是我不能忽略我的分组,因为我会得到双行。有什么建议吗? 最佳答案
要将投影添加到DetachedCriteria,请使用setProjection()方法,如下例所示:
DetachedCriteria criteria = DetachedCriteria.forClass(Dossier.class);
criteria.add(Restrictions.eq("firstName", critere.getFirstName()));
criteria.add(Restrictions.eq("secondName", critere.getSecondName()));
criteria.setProjection(Projections.groupProperty("iddossier"));
关于java - DetachedCriteria-分组依据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25545686/