I am trying to construct a criteria that will provide an AVG of a field from the returned set of objects from a search. The first part of the criteria works fine. The restriction on type. But I can't get the avg function to return a single result. I get an error on the execution of the getSingleResult() method that there are multiple rows.
So, I have the search and the criteria as follows:
Session session = (Session) getDao().getEntityManager().getDelegate(); Criteria query = session.createCriteria(Tattle.class, "t"); query.add( Restrictions.eq("t.type", "tattle")); query.setProjection( Projections.projectionList().add( Projections.avg( "t.points" )));
luceneQuery = parser.parse("text:" + searchQuery + " OR " + "subject:" + searchQuery); fq = fullTextEntityManager.createFullTextQuery(luceneQuery).setCriteriaQuery( query );
// run the search query averageRating = (Long)fq.getSingleResult();
|