• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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%'..
 
reply
    Bookmark Topic Watch Topic
  • New Topic