All,
Is it possible to use the Criteria API to select additional columns in addition to the root entity?
For example -- assume we have a Person entity with Name, Age, etc. We want to construct a query using the Criteria API which will select everyone in the table who is 35 years old while also selecting a few additional columns (or SQL expressions) which aren't mapped as part of the Person entity.
It seems like a ResultTransformer could perhaps be used to work with the result of such a query, but I can't seem to find any way to add the additional columns to the query. Projections sort-of do this, but they don't select the root entity -- and we want to select the root entity along-side the additional expressions.
To give a more practical example: Given an entity, ShoppingMall, which has name, streetAddress, city, state, zip and a geocode, we want to select all the shopping malls in a given city and, in the same query, use the database's spatial capabilities to get the distance from a user specified location to that mall. This would require selecting an extra SQL expression (SDO_DISTANCE() in Oracle, for example) in addition to the columns required for the ShoppingMall entity.
|