• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Alternative to LIKE Clause

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I would like use clause LIKE in my EJB-QL query. Like this: . But it doesn�t works. Reading other posts and forums, I perceived that it is not possible use LIKE with parameter, only with constants.
So I tried other alternative. I wrote my query this: . It works!
Now, I want your opinion. Is this a acceptable alternative? Or is this a ugly patch?
Thanks,
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a...
<finder>
<name>findByStartsWithAndLocale</name>
<query>entry LIKE "{0}%" AND locale = {1}</query>
<order></order>
</finder>
block in my JAWS.xml. It works fine. Maybe it was the surrounding characters of your arg.
Good luck.
 
Rafael Afonso
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Matthew Webster:
I have a...
<finder>
<name>findByStartsWithAndLocale</name>
<query>entry LIKE "{0}%" AND locale = {1}</query>
<order></order>
</finder>
block in my JAWS.xml.


Matthew:
I've never saw a query like yours. From I read We use "?1" for parameters not "{0}". Is this a Extension to EJB-QL of JBoss?
Thanks,
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that is a brilliant solution! couldn't find it anywhere else. You are a very smart man. Thanks for sharing that!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using now JBoss 4.2.3.GA and that SUBSTRING doesn't seem to work for this purpose anymore.

But I tried this and it worked for me:


This simulates the query:


You can even do a CONCAT(CONCAT('%', ?1), '%') if you need something like '%?1%' instead.
 
Evil is afoot. But this tiny ad is just an ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic