Hi I am trying to query my database by a specific property. Multiple entries in my database may have the same value for the property but I want it to return only the first entry that has that distinct value for the property.
For example, if my domain has a code
property, then there might be an entry where "code" = "boy"
, and there might be another one where "code" = "girl"
and there might be yet another one where again "code" = "boy"
. I want to query it so I get the first entry where "code" = "boy"
and the entry where "code" = girl"
but not the third entry where code
is again equal to boy
.
I was able to get the distinct code
values from the database using both createCriteria()
or namedQueries()
but I am not able to get the whole object, just the value of code
. How can I get the actual object?