Intuitively, what I want to do is something like this:
Restrictions.ilike("concat(user.firstName, ' ', user.lastName)",
text.toLowerCase() + "%")
However, I know that this won't work, because concat(user.firstName, ' ', user.lastName)
is not a property that Hibernate understands, even though this is what I would have typed in a regular SQL statement as part of the where clause.
Is there any easy way to make this where restriction with Hibernate Criteria API, or do I have to fall back on good-old HSQL?
Thanks
One solution is to define fullName
property in your User
class.
@Formula(value="first_name || ' ' || last_name")
private String fullName;
And then use that filed in Criteria
,
criteria.add(Restrictions.ilike("fullName", text.toLowerCase() + "%"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With