Reputation: 1724
I need to construct a hibernate query that would do something like this:
select p from Person p where (p.name, p.surname) in (('Peter', 'Black'), ('Thomas', 'Peterson'), ('Julia', 'Cook'))
The length of the name/surname list is not defined upfront and the name and surname can contain any characters (the name and surname naming is used just for the illustration purposes)
Also I would like to insert the values as a query parameter to prevent sql injection.
solutions that is not acceptable:
(p.name || '--' || p.surname) in (:mergedNameSurname)
solution that I would like to avoid:
((p.name = :name1 and p.surname = :surname1) or (p.name = :name2 and p.surname = :surname2) ...)
Do you have some idea how this could be done?
Upvotes: 1
Views: 750
Reputation: 5357
I do not think there is a clean Hibernate solution for this. You either take one of the two approaches you suggested or add a denormalized column which represents the concatenation of the two columns. Even with that approach you will end up building something similar to your final query though.
Upvotes: 1