DetachedCriteria类中uniqueResult()方法与list()方法区别
1
2
3
4
5
6
|
DetachedCriteria criteria = new RecruitmentCriteria().createForDealer(dealerId, jobTitleId) .dateFilterForSM(year, month) .candidateFilterForSM(candidateId) .finalAssessmentResultPassed().build(); Integer count = (Integer) criteria.getExecutableCriteria(getSession()).uniqueResult(); if (count > 0 ){<br> return true ;<br>} |
DetachedCriteria构建检索条件时,有两个方法.uniqueResult()与.list(),
采用前者uniqueResult()方法,如果查询结果为1条,则返回值为1;查询结果为0条,则返回0;查询结果大于1条,则抛出异常NonUniqueRequestException.
采用后者list()方法,检索时bibernate会为在底层拼上count(*),因此返回值为0或正整数。