I am trying to improve performance of an api. I need to know whether the second line that's marked will hit database too ? as I want to minimise that.
StringBuffer queryBuf = new StringBuffer("some query in SQL");
--------->StringBuffer queryBuf2 = new StringBuffer(" SELECT DISTINCT PP.ID FROM ( " + queryBuf + ") PP ");
Query query1 = getSession().createSQLQuery(queryBuf2.toString());
query1.setReadOnly(true);
ScrollableResults results = query1.scroll();
if (results.isLast() == false)
results.last();
int total = results.getRowNumber() + 1;
results.close();
logger.debug(">>>>>>TOTAL COUNT<<<<<< = {}", total);