Get unique Hibernate results
I have a table named PageView which contains the fields id, ip, userAgent,
page and visitDate.
Now, to get only unique visitors (not all pageviews) I need to avoid
duplicate IPs.
Currently I have
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
createCriteria(PageView.class)
.add(Restrictions.lt("visitDate", cal.getTime())).list()
for getting the result set (to show counter stats for yesterday, today and
now) and
((Number) createCriteria(PageView.class)
.setProjection(Projections.countDistinct("ip")).uniqueResult()).intValue()
for counting them (to show counter stats for total).
How to use the Criteria API to realize this?
No comments:
Post a Comment