aspose file tools
The moose likes Object Relational Mapping and the fly likes How do I do a 'like' with a numeric value using entities? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "How do I do a Watch "How do I do a New topic
Author

How do I do a 'like' with a numeric value using entities?

Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 364
Hi all -
I want to use a like clause with a long

e.g. where id like '123%' ....

using Hibernate's query.setParameter I run into a problem:
query.setParameter( id, "123%") complains because the value is a long and I'm passing a String

do I need to code a native query?

thanks
Max
Jason Kwok
Ranch Hand

Joined: Mar 31, 2005
Posts: 126
This is a HUGE stab in the dark because I haven't used Hibernate before and as such, I may be completely off base here, but this looks similar to using a PreparedStatement which I've used to work with MySQL. Try this:

... where ((id) Like ?)

query.setParameter(1, "123%");
[ July 06, 2007: Message edited by: Jason Kwok ]
Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 364
I tried that but it complains because the parm is a String, not a Long...native sql works because soem conversion is done from the '123%'..
 
jQuery in Action, 2nd edition
 
subject: How do I do a 'like' with a numeric value using entities?
 
Threads others viewed
@ManyToMany and Select query
Response xml in Apache CXF using JAX-RS
trim on where clause
GOTO in JSF?
List values are not bind with text fields
developer file tools