I\'m trying to crete Criteria API query with CONTAINS function(MS SQL):
select * from com.t_person where contains(last_name,\'xxx\')
CriteriaBuilder
If you want to stick with using CONTAINS, it should be something like this:
//Get criteria builder
CriteriaBuilder cb = em.getCriteriaBuilder();
//Create the CriteriaQuery for Person object
CriteriaQuery query = cb.createQuery(Person.class);
//From clause
Root personRoot = query.from(Person.class);
//Where clause
query.where(
cb.function(
"CONTAINS", Boolean.class,
//assuming 'lastName' is the property on the Person Java object that is mapped to the last_name column on the Person table.
personRoot.get("lastName"),
//Add a named parameter called containsCondition
cb.parameter(String.class, "containsCondition")));
TypedQuery tq = em.createQuery(query);
tq.setParameter("containsCondition", "%näh%");
List people = tq.getResultList();
It seems like some of your code is missing from your question so I'm making a few assumptions in this snippet.