2012-11-16 70 views
0

請幫我這個。DetachedCriteria - 如何將分離標準結果轉換爲整數?

我使用分離標準來獲得客戶總數。

在我CustomerDaoImpl:

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

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

通常我做的是我得到的結果,存儲在一個集合中,並使用collection.size。我不認爲它的高效率,因爲我必須獲取不必要的數據才能獲得count。請幫忙。

回答

2
Number result = (Number) dc.getExecutableCriteria(session).uniqueResult(); 
return number.intValue(); 
相關問題