由于不推荐使用.createCriteria(),如何从标准将冬眠更新为CriteriaBuilder?

时间:2019-06-12 14:08:12

标签: java hibernate spring-boot criteria

必须遵循以下代码,如何使用CriteriaBuilder和QueryCriteria更新它?

public Object getNR(String su, String tu, long tst, int nrOfChanges)
throws HibernateException {
Criteria cr = getCurrentSession().createCriteria(MyClass.class);

cr.add(Restrictions.gt("Tst", tst));

Criterion cr1 = Restrictions.and(Restrictions.eq("TU", tu));
Criterion cr2 = Restrictions.and(Restrictions.eq("SU", su))
.add(Restrictions.and(Restrictions.eq("CT", ct)));

cr.add(Restrictions.or(cr1, cr2));
cr.setProjection(Projections.rowCount());
Long nr = (Long) cr.uniqueResult();


return null;
}

0 个答案:

没有答案