-->
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: Hibernate search with FullTextSession&Criteria
PostPosted: Fri Apr 08, 2011 8:55 am 
Newbie

Joined: Fri Apr 08, 2011 8:44 am
Posts: 8
Hi,
I am doing hibernate search with Lucene,
I want to get count of distinct userId and count of tweets from the lucene result
see the below code:

Criteria joinCriteria =session.createCriteria(MBlogLiveTweetVO.class)
.setProjection(Projections.projectionList().add(Projections.countDistinct("userId"))
.add(Projections.count("tweet")));

FullTextQuery fullTextQuery = fSession.createFullTextQuery(lucenceQuery).setCriteriaQuery(joinCriteria);
System.out.println("Result -->"+fullTextQuery.list());

Also i enabled show_sql =true in hibernatec.fg.xml file to verify the result.

The output result is Zero record.but record is there If i execute printed SQL query (like below)
select count(distinct this_.user_id) as y0_ from mblog_live_tweets this_ where (this_.tweet_id in (?))

Kindly let me know what's the problem with my code.


Top
 Profile  
 
 Post subject: Re: Hibernate search with FullTextSession&Criteria
PostPosted: Fri Apr 08, 2011 10:03 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
What you are doing is actually not supported. Criterias should only be used to specify the fetch mode for joins. The documentation says:

Quote:
Only fetch mode can be adjusted, refrain from applying any other restriction.


Quote:
One cannot use setCriteriaQuery if more than one entity type is expected to be returned.


We always recommend to index all the information you need to solve your search requirements via Lucene queries. Also don't get confused between Hibernate Core porjections and Hibernate Search projections. These are different beasts.
I recommend you have another look at the Hibernate Search docs.

--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.