You have three options:
1) If you are not pinned to Critera api, I recommend to use HQL instead of Criteria API
Date d = new SimpleDateFormat("yyyy-MM-dd").parse("2014-10-12");
Query query = session.createQuery("select count(*) from Visit v where trunc(v.date)=:date and v.visitor.id=:visitorId");
query.setParameter("date", d);
query.setParameter("visitorId", 1L);
Long count = (Long) query.uniqueResult();
2) If you want to use Criteria API, it’s possible to apply sqlRestriction. Unfortunately you will lock to specific database. This example works on HSQLDB
Date d = new SimpleDateFormat("yyyy-MM-dd").parse("2014-10-12");
Long count = (Long) session.createCriteria(Visit.class)
.setProjection(Projections.rowCount())
.add(Restrictions.eq("visitor.id", 1L))
.add(Restrictions.sqlRestriction("trunc(date)=?", d, org.hibernate.type.StandardBasicTypes.DATE))
.uniqueResult() ;
3) It’s also possible to use pure criteria API, but date restriction must be a little bit hacked (using between restriction)
Date d = new SimpleDateFormat("yyyy-MM-dd").parse("2014-10-12");
Date maxDate = new Date(d.getTime() + TimeUnit.DAYS.toMillis(1));
Long count = (Long) session.createCriteria(Visit.class)
.setProjection(Projections.rowCount())
.add(Restrictions.eq("visitor.id", 1L))
.add(Restrictions.between("date", d, maxDate))
.uniqueResult();