How to compare an uppercase query with JPA and the QueryBuilder -


how compare uppercase jpa querybuilder?

sql:

select * person upper(name) = ? 

and add: searchname.touppercase()

here solution:

public list<person> getpersonsbyuppername(string searchname) {     criteriabuilder cb = em.getcriteriabuilder();     criteriaquery<person> cq = cb.createquery(person.class);     root<person> person= cq.from(person.class);      path<string> name = person.get("name"); //table column      cq.select(person);     cq.where(cb.equal(cb.upper(name), cb.parameter(string.class, "nameupper")));      typedquery<person> q = em.createquery(cq);     q.setparameter("nameupper", searchname.touppercase());;      return q.getresultlist(); } 

this works input string (dimitri, dimitri, etc.) uppercase conversion performed inside method:

  • table column: cb.upper(name)
  • query parameter: searchname.touppercase()

i hope helps.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -