Matt Bearson
Matt Bearson

Reputation: 238

JPA multiple search in two fields by string

I have input string, like that "part of name and part of surName"
And in my entity I have two fields: name and surName. And i want fold this two fields name + " " + surName and then search my text "part of name and part of surName" in this new String from two fields.
Can I create this query in JPA? Or i must choose separately this fields and then already on Java BE, fold them and start search by string also on BE?

Upvotes: 0

Views: 859

Answers (1)

JB Nizet
JB Nizet

Reputation: 691865

select p from Person p 
where concat(p.name, ' ', p.surname) like concat('%', :part, '%')

Upvotes: 3

Related Questions