0

I have a project based in Spring Web model-view-controller (MVC) framework. The version of the Spring Web model-view-controller (MVC) framework is 3.2.8.

I have this method in my DAO

@Override
    public List<Application> findByQuickSearch(String searchString) {

        final StringBuilder queryString = new StringBuilder("  select app from Application app where upper (ticket_id) like :searchString or upper (id) like :searchString " );

        queryString.append(" and app.status != " + Status.DRAFT.ordinal());

        queryString.append(" order by app.submissionTime desc ");

        try {

            final Query query = getEntityManager().createQuery(queryString.toString());

            searchString = searchString.replace("!", "!!")
                       .replace("%", "!%")
                       .replace("_", "!_")
                       .replace("[", "![")
                       .trim()
                       .toUpperCase();


            System.out.println ("searchString -----> " + searchString);


            query.setParameter ("searchString", searchString);                      

            return query.getResultList();


        } catch (RuntimeException re) {
            log.error("findByCompetentBodyAndStatus failed", re);
            throw re;
        }
    }

But I realized that the query does not do LIKE but equals

the spring I am looking for is "iOS/032/027" , ok for "iOS/032/027", but not for "iOS/" or "027"

Amadeu Cabanilles
  • 913
  • 3
  • 19
  • 47

1 Answers1

0

Try appending a valid wildcard to the like operation:

str_param like concat(:searchString,'%') 

The Jpql doc states

LIKE evaluates if the two string match, '%' and '_' are valid wildcards, and ESCAPE character is optional

Alex Ciocan
  • 2,272
  • 14
  • 20