java - JPA Criteria api with CONTAINS function -


i'm trying crete criteria api query contains function(ms sql):

select * com.t_person contains(last_name,'xxx')

criteriabuilder cb = em.getcriteriabuilder(); criteriaquery<person> cq = cb.createquery(person.class); root<person> root = cq.from(person.class);  expression<boolean> function = cb.function("contains", boolean.class,  root.<string>get("lastname"),cb.parameter(string.class, "containscondition")); cq.where(function); typedquery<person> query = em.createquery(cq); query.setparameter("containscondition", lastname); return query.getresultlist(); 

but getting exception: org.hibernate.hql.internal.ast.querysyntaxexception: unexpected ast node:

any help?

if want stick using contains, should this:

//get criteria builder criteriabuilder cb = em.getcriteriabuilder(); //create criteriaquery person object criteriaquery<person> query = cb.createquery(person.class);  //from clause root<person> personroot = query.from(person.class);  //where clause query.where(     cb.function(         "contains", boolean.class,          //assuming 'lastname' property on person java object mapped last_name column on person table.         personroot.<string>get("lastname"),          //add named parameter called containscondition         cb.parameter(string.class, "containscondition")));  typedquery<person> tq = em.createquery(query); tq.setparameter("containscondition", "%näh%"); list<person> people = tq.getresultlist(); 

it seems of code missing question i'm making few assumptions in snippet.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -