[Already posted to hibernate-users, but no responses.]<br><br>Hi,<br><br>I have pagination working, but am doing so with two queries; one to get the results page and a second one to get the total count.<br><br>I'd like to do this in a single query: Is it possible to build a criteria, so my results set includes columns for each of the properties on my bean, plus an additional column which has the row count (downside: this is duplicated for each row in the page).<br>
<br>I figured I could build a projection like this to return all the beans properties plus the row count.<br><br>private Projection getProjectionsForBeanAndRowCount() {<br>ClassMetadata classMetadata = session().getSessionFactory().getClassMetadata(modelClass);<br>
<br>ProjectionList projectionList = Projections.projectionList();<br>projectionList.add(Projections.rowCount());<br>String[] propertyNames = classMetadata.getPropertyNames();<br>for (String propertyName : propertyNames) {<br>
projectionList.add(Projections.property(propertyName));<br>}<br>return projectionList;<br>}<br><br>..and then write a ResultsTransformer to process these results, instantiating a class like:-<br><br>public class PageResult {<br>
Object bean;<br>int rowCount;<br>}<br><br>..but it seems that by the time ResultsTransformer is called, you already have the bean instantiated.<br><br>Is there a way I can jump in at a slightly lower level, like at a single row of the result set, the level where the results bean's are built?<br>
<br>Any info much appreciated.<br><br>All the best, Jon<br>