I am moving from Criteria to HQL and enjoying the process, but have a a question.
I have a class "Person" with a one-to-many set of objects "Metadata". Metadata are simple objects; they only have a String key and a String value.
I would like to use HQL to query for person objects based on multiple metadata constraints.
For example, I want to find people objects with two types of specific types of metadata.
Code:
"Select distinct ppl from Person as ppl " +
"join ppl.metadata as meta " +
"where " +
"(meta.key='hair_color' and meta.value='red') " +
"and " +
"(meta.key='eye_color' and meta.value='green') "
This doesn't return anything, even though there are people objects with red hair and green eyes in my database....
This is probably because I am asking for a specific metadata object's value ("key") to be two things at the same time.
If I use an 'or', I get results back, but I want red-haired green-eyed people specifically.
How should I express my desire to search though a set this way? Thanks.