-->
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.  [ 1 post ] 
Author Message
 Post subject: Criteria to allow custom SELECT SQL to an Annotated Class
PostPosted: Tue Feb 08, 2011 6:36 pm 
Newbie

Joined: Tue Feb 08, 2011 6:24 pm
Posts: 1
Hi, I am trying to execute the following query using DetachedCriteria:

SELECT *, MATCH(postContent, postTitle) AGAINST ("ferrari porsche lambo") as Relevance
FROM POST
WHERE MATCH (postContent, postTitle) AGAINST("ferrari porsche lambo" IN BOOLEAN MODE)
ORDER BY Relevance DESC

As you can see from the query I am implementing FULLTEXT searching against my database. What I need is to use getHibernateTemplate().findByCriteria(criteria, rowNum, itemsPerPage); for pagination purposes.

Does anyone know how to use DetachedCriteria to add the Relevance alias to the query? This is not working due to Relevance not being on the Post bean...which it won't be since I want a dynamic query.

Here is the Java source:

Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Post.class);
criteria.createCriteria("MATCH (postContent, postTitle) AGAINST ('"+searchCriteria+"' IN BOOLEAN MODE) as Relevance");   
criteria.add(Restrictions.sqlRestriction("MATCH (postContent, postTitle) AGAINST('"+searchCriteria+"' IN BOOLEAN MODE)"));
criteria.addOrder(OrderBySqlFormula.sqlFormula("Relevance DESC"));
postList = getHibernateTemplate().findByCriteria(criteria, rowNum, itemsPerPage);


This generates the following error since Relevance is not on the Post bean:
org.springframework.orm.hibernate3.HibernateQueryException : could not resolve property: MATCH (postContent, postTitle) AGAINST ('ferrari' IN BOOLEAN MODE) as Relevance of: domain.Post;

I have searched for many hours on this issue with no luck. I basically need a pointer to correct the second line of code in my Java source to properly generate the hibernate query.


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

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.