Code example for DetachedCriteria

Methods: addsetProjection

0
	 */ 
	@SuppressWarnings("unchecked") 
	@Override 
	public List<Long> getRandomIds(Integer maxResults) {
		DetachedCriteria criteria = this.createDetachedCriteria();
		criteria.setProjection(Projections.id());
		criteria.add(getRandomRestriction());
		return this.getHibernateTemplate().findByCriteria(criteria, 0, maxResults);
	} 
	 
	/** 
	 * Find random results that fulfill the given criteria. 
	 *  
	 * @param criteria The {@link DetachedCriteria} to fulfill. 
	 * @param maxResults Maximum quantity of results to find. 
	 * @return The random list. 
	 */ 
	protected List<T> findRandomList(DetachedCriteria criteria, Integer maxResults) {
		criteria.add(getRandomRestriction());
		return find(criteria, maxResults);
Experience pair programming with AI  Get Codota for Java