-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Using an aggregation in a search criteria
PostPosted: Fri Jul 16, 2010 7:52 pm 
Newbie

Joined: Thu Jul 15, 2010 11:37 pm
Posts: 1
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();


Top
 Profile  
 
 Post subject: Re: Using an aggregation in a search criteria
PostPosted: Sun Jul 18, 2010 7:32 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Mixing and matching Lucene queries (fulltext queries) with Hibernate Criteria queries is not supported. The documentation uses Criteria to specify a fetch type, but otherwise recommends against applying additional criteria.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.