-->
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: native queries
PostPosted: Wed Jun 08, 2005 10:17 am 
Beginner
Beginner

Joined: Wed Jun 08, 2005 10:01 am
Posts: 22
Location: Italy
Hi to all!
I am using a native query in MySQL to find a match in a fulltext field (I have to use the MATCH ...AGAINST function in MySQL).
I can retrieve the result of my query:

private static String SQLQuery = "SELECT {users.*} FROM users WHERE MATCH(firstName, lastName, email, address, city, province, state, nationality, phone, mobile, profession, attributes) AGAINST(:search)";

here the Java method to get it from Hibernate:

/**
* Searches information in fulltext fields
* @param string
* @return
* @throws BusinessException
*/
public List searchInfo(String string) throws BusinessException {
try {
Session session = HibernateUtil.currentSession(); return session.createSQLQuery(SQLQuery).addEntity("users", HBUser.class).setString("search", string ).setMaxResults(50).list();
} catch (HibernateException e) {
throw new BusinessException(e);
}
finally{
HibernateUtil.closeSession();
}
}


It works, but I am not satisfied and i want to get the score of the MySQL's function MATCH...AGAINST. So I added the following to my query:

MATCH(firstName, lastName, email, address, city, province, state, nationality, phone, mobile, profession, attributes) AGAINST(:search) as score

Here the complete final query:

private static String SQLQuery = "SELECT {users.*}, MATCH(firstName, lastName, email, " +
"address, city, province, state, nationality, " + "phone, mobile, profession, attributes) AGAINST(:search) as score FROM users WHERE MATCH(firstName, lastName, email, " + "address, city, province, state, nationality, " +
"phone, mobile, profession, attributes) AGAINST(:search)";


How can I retrieve the score from Hibernate? I don't have mapped it into the POJO class.
Is the a specific method to retrieve a renamed field from a native query?

Thank you in advance for your time,
Nicola


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 12:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use hibernate 3 and read about scalar native queries in the reference doc.

_________________
Max
Don't forget to rate


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.