I'm using the accepted method of obtaining the number of rows from an HQL query:
Code:
query.scroll().last().getRowNumber() + 1;
and it's working ... half the time. After some investigation, I learned that there are two implementations of ScrollableResults being used:
FetchingScrollableResultsImpl and
ScrollableResultsImpl, and they use different bases for determining the row number.
From
FetchingScrollableResultsImpl - one-based:
Code:
public boolean isFirst() throws HibernateException {
return currentPosition == 1;
}
public int getRowNumber() throws HibernateException {
return currentPosition;
}
From
ScrollableResultsImpl - zero-based:
Code:
public int getRowNumber() throws HibernateException {
try {
// The underlying JDBC ResultSet is one-based.
return getResultSet().getRow()-1;
}
catch (SQLException sqle) {
...
}
}
Now, this looks like a bug, and smells like a bug, but I'm a cautious fellow so I thought I'd seek the counsel of those more experienced than I am for their opinion.
I'm using Hibernate 3.3.1.GA.
Cheers,
Steven.