-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL: how to use 'between' with text field
PostPosted: Wed Feb 20, 2008 5:35 am 
Newbie

Joined: Sat Jan 14, 2006 8:03 pm
Posts: 18
I have a table, Address, with a couple fields, 'numStart' and 'numEnd'. When a user searches for Addresses he can specify the Street name and optionally, a Number. I would like to do a query like this:

from Address where street.name like ? and and ? between numStart and numEnd

The only problem is that 'numStart' and 'numEnd' are TEXT fields, not numbers. (I inherited the database ...) So HQL chokes. If I run the equivalent SQL query directly in mySql it works, it seems to convert the text field values to numbers on the fly.

Can I do this with HQL?

Thanks,
Bob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 5:58 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
Hi,
If you compare the number with varchar column in sql then number will be automatically converted into string(Note that values in that column value must be number - only column type is varchar). This is rthe reason sql is working fine.


If you want to do this in HQL then,

use setString() of Query object to set the number in your example. Again note that value in 'numStart' and 'numEnd' must be number value.


Top
 Profile  
 
 Post subject: HQL: how to use 'between' with text field
PostPosted: Wed Feb 20, 2008 11:08 am 
Newbie

Joined: Sat Jan 14, 2006 8:03 pm
Posts: 18
Cool, I'll give it a try. Since I am using Spring with Hibrnate, up until now I have been using Spring's getHibernateTemplate() but I guess I can use a Query object. I'll let the list know if it worked, many thanks.

Bob


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.