I’m not sure how to approach queries that don’t map 1:1 to my persistent entities – in other words, distinct and aggregate queries. For example, I need to retrieve a distinct list of property values for populating a drop-down list.
Should I write a class and a mapping for the “entities” that are returned by this query? Or should I just use the native DB provider and work with native data sets instead?
If I understand correctly, your problem can be solved by scalar queries in HQL. For example:
You can also use
distinctin such queries.Here is another example.
Of course the same can also be done using native SQL from within Hibernate.