• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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%'..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic