1 Reply Latest reply on Oct 17, 2006 5:03 AM by r_mun

    ejbql - problem with like and named parameter

    adamzrk

      When I invoke this in ejb:

      query = "select book from Book book join book.title t join t.authors a where (upper(a.firstName)||' '||upper(a.lastName)=upper(:auth) or upper(a.lastName)||' '||upper(a.firstName)=upper(:auth)) and upper(t.title) like '%upper(:title)%' and book.price between :pr and :pr2";
       return manager.createQuery(query).setParameter("title",title).setParameter("auth",author).setParameter("pr",priceFrom).setParameter("pr2",priceTo).getResultList();
      


      i get the exception:
      Caused by: javax.ejb.EJBException: javax.persistence.PersistenceExcepti
      ibernate.HibernateException: could not locate named parameter [title]

      Anyone knows what's wrong?

        • 1. Re: ejbql - problem with like and named parameter
          r_mun

          Hi, Adam

          I have faced the same problem. You have probably found the sollution youself.
          Just for the protocol I'll add my sollution to this problem so that others could use it.

          The query I formed was like

          SELECT distinct object(o) FROM Rental o WHERE lower (o.description) LIKE lower('%:fullTextSearch%')


          later in the code an attribute was set via (q is a an EJB3 Query object)
          q.setParameter("fullTextSearch", aSubStringToSearchFor);


          After playing with parameters and code I finally did the following changes that fixed the issue.

          SELECT distinct object(o) FROM Rental o WHERE lower (o.description) LIKE lower(:fullTextSearch)


          and the attribute setter like
          q.setParameter("fullTextSearch", "%" + aSubStringToSearchFor + "%");



          The problem is obviously that Hibernate is not capable of setting a parameter within single-quoted statements.

          Regards,
          Roman Muntyanu
          http://www.yukon.cv.ua