• 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

EJBQL

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, what I am trying to do is set up a search based on three fields. One is an integer, the other two are strings.

I have a working EJB 3.0 Entity Bean and a stateless session bean in front of it. What I want to do is set up a named query that I can call to perform the search.

My problem is that I can not find a way to do "LIKE" with the Integer field. It works fine with the String but not with the Integers.

I want to be able to type in "21" and return all results with "21" ANYWHERE in the integer field (321, 213, 113211, etc).

Here is what I've tried:
@NamedQuery(name="findRoyaltyContractLikeRoyaltyContractKey",
query="SELECT OBJECT(rc) FROM RoyaltyContractBean rc " +
"JOIN rc.royaltyContractOwner rco " +
"WHERE (rc.royaltyContractId LIKE :id) " +
"AND (rco.supplierCode LIKE wner) " +
"AND (rc.vendor LIKE :vendor)")

The royaltyContractId being the integer field that I am having trouble with. Is there a trick to getting LIKE to work with Integers in EJBQL?

Thanks in advance for your time!
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately there is no LIKE for interger. What you could do is to transform it into a string and then apply a LIKE on it but I am not sure how this would be done in EJBQL (I only would know it for Oracle).

-Andy
 
Thomas Busch
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, this seems to work

select * from royaltyContract WHERE convert(varchar(10), royaltycontractid) LIKE '%21%'

So I will see about translating that into EJBQL. Thanks though, you're right I guess there's no good way to do a "like" comparison on integers!

-Tom
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic