Karthik
Karthik

Reputation: 470

Spring predicate jpa query issue

I am written a predicate query to concat firstname and lastname and compare with entered character.But, I am not able to get the desired result.

QUser user = QUser.suer;
BooleanExpression exp = user.isNotNull();
String received = "Jack Jones"
expression =  expression.and((userProfile.firstName.toLowerCase().concat(" "    + userProfile.lastName.toLowerCase())).like('%'+(received)+'%'));

I am not getting the record with Jack Joneas when I type in front end. What is need to be done to resolve issue.

Upvotes: 0

Views: 349

Answers (1)

Simon
Simon

Reputation: 857

Your (Java) expression " " + userProfile.lastName.toLowerCase() calls the toString() method of the second argument, producing an undefined, fixed String expression instead of a dynamic expression.

What you actually want to achieve is to concatenate 3 parts:

  • the first name
  • a constant space
  • the last name

So your last line of code should look like this:

expression =  expression.and((userProfile.firstName.toLowerCase().concat(" ").concat(userProfile.lastName.toLowerCase())).like('%'+(received)+'%'));

Upvotes: 1

Related Questions