Let me describe the question in full details to avoid the X-Y situation.
I want to use Hibernate to do a LIKE
query to retrieve registries in table Product
where the Product
's User
has my input string as full name. Something in SQL like:
SELECT * FROM product WHERE id_user IN (SELECT id_user FROM users WHERE CONCAT(first_name, ' ', last_name) LIKE ?)
I am happy with Hibernate Criteria, but in this case it seems to have no way to do combining columns values searching in Criteria (I don't want to generate some customized Criteria aside), so I am trying to use Restriction.sqlRestriction()
, but I found that in some case createAlia()
is quite easy while sqlRestriction
is impossible, such as:
criteria.createAlias("user.supervisor.teamleader", "uT");
So, I am considering another solution: creating a @Transient
field in User
to store the full name, concatenating first_name
, " "
, and last_name
, because now a column named full_name
doesn't exist in database, and I don't want to touch table structure, which requires modification to production database.
If I declare full_name
field in the default constructor of User
class, when I retrieve some User
entity from database, will this field holds first_name + " " + last_name
as I expect, or will it be null
?