我使用分离进行搜索,并且我使用分组依据。我的代码如下:
@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(...)
是问题,但我不能忽视我的小组,因为我会得到一条双线。有什么建议吗?
答案 0 :(得分:1)
要向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"));