Register / Login
this forum made possible by our volunteer staff, including ...
Roel De Nijs
Stephan van Hulst
Object Relational Mapping
Getting started with HQL - how to query on sets?
posted 8 years ago
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
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.
"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.
I express my desire to search though a set this way? Thanks.
It is sorta covered in the
JavaRanch Style Guide
Boost this thread!
Hibernate Query column number mismatch
HQL help needed
Loading the metadata of the table
retrieve a single value inside string