1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.