0

I want to convert my sql query from SQL to Criterias (i dont want to use JPQL), i have this sql query:

SELECT * FROM (
SELECT CONCAT_WS(' ',p.first_name, p.middle_name, p.last_name) AS fullname FROM persons p) AS tmp
WHERE fullname LIKE '%cetina avila%' ORDER BY fullname;

How is the best way to do this?, Im trying to search full names from my talbe persons.

Thanks

maxtorzito
  • 308
  • 7
  • 14

1 Answers1

1

One way to do this is to use an @Formula mapping on your Person class like this

@Formula("CONCAT(first_name, ' ', middle_name, ' ', last_name)")
private String fullname;

Then in your Criteria you can search it like any normal field.

See Calculated property with JPA / Hibernate for more on calculated fields.

Community
  • 1
  • 1
carbontax
  • 2,164
  • 23
  • 37