• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJBQL  RSS feed

 
Thomas Busch
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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!
 
Andreas Schaefer
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!