@ SuppressWarnings ( "unchecked" ) public PagingResult < E > findByCriteriaWithSortingAndPaging ( Integer firstResult , Integer maxResults , List < Order > sorters , Criterion ... criterion ) throws HibernateException { int nrOfSorters = sorters == null ? 0 : sorters . size ( ) ; LOG . trace ( "Finding instances of " + entityClass . getSimpleName ( ) + " based on " + criterion . length + " criteria" + " with " + nrOfSorters + " sorters" ) ; Criteria criteria = createDistinctRootEntityCriteria ( criterion ) ; // add paging info if ( maxResults != null ) { LOG . trace ( "Limiting result set size to " + maxResults ) ; criteria . setMaxResults ( maxResults ) ; } if ( firstResult != null ) { LOG . trace ( "Setting the first result to be retrieved to " + firstResult ) ; criteria . setFirstResult ( firstResult ) ; } // add sort info if ( sorters != null ) { for ( Order sortInfo : sorters ) { criteria . addOrder ( sortInfo ) ; } } return new PagingResult < E > ( criteria . list ( ) , getTotalCount ( criterion ) ) ; }
Gets the results that match a variable number of passed criterions considering the paging - and sort - info at the same time .