1 Reply Latest reply on Aug 10, 2002 12:34 PM by dsundstrom

    EJB-QL LIKE

    ruzmelin

      I have a database column called 'name', which
      contains a list of names of users. I would like for that entity's home
      interface to contain a method with the signature:


      public Collection findByKeyword(String keyword) throws FinderException;


      However, I don't know how to write the EJB-QL such that it executes the
      equivalent SQL:


      select * from content where keywords like '%stuff%

      I've tried something like
      <ejb-ql>SELECT OBJECT(a) FROM Users a WHERE a.name LIKE '%?1%'</ejb-ql>

      but it doesn't work.
      I've even tried some trick like this

      ....
      findByKeyword("%"+keyword+"%")
      ....
      <ejb-ql>SELECT OBJECT(a) FROM Users a WHERE a.name LIKE ?1</ejb-ql>

      but it produces an exception at deploy time.

      Some suggestion?

      Thanks a lot...

        • 1. Re: EJB-QL LIKE
          dsundstrom

          In the furture you will be able to use string function in the like clause in JBossQL (it was just an over site). In the mean time I suggest you preprocess the input parameter in code to add the % to the begining and end. I would do the follwoing:

          change findByKeyword in the Home to selectByKeyword
          add the ejbHomeSelectByKeyword method to the Impl class
          have the new method modify the keyword call an ejbSelect method
          map the ejbSelect method to a JBossQL query in the jbosscmp-jdbc.xml file.

          BTW, you have to use JBossQL instead of EJB-QL as EJB-QL does not allow parameters in a LIKE clause.