0

Please help me with this.

Im using detached criteria to get the total number of customers.

In my CustomerDaoImpl:

@Override
public int getCustomerSize() {
    DetachedCriteria dc = getDetachedCriteria();
    dc.setProjection(Projections.count("customerId"));

    // I need to return only the count result.
    return 0;
}

Usually what I do is I get the results, store in a collection and use the collection.size. I don't think its efficient for I have to fetch the unnecessary data just to get the count. Please help.

tereško
  • 58,060
  • 25
  • 98
  • 150
NinjaBoy
  • 3,715
  • 18
  • 54
  • 69

1 Answers1

2
Number result = (Number) dc.getExecutableCriteria(session).uniqueResult();
return number.intValue();
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255