Joined: Wed May 12, 2004 6:22 pm Posts: 4
|
We are using the Criteria exclusivly throughout our application. Each query we call list() to get the results. The criteria is limited by MaxResults and the FirstResult is set so that our results get paginated within the application. Then we remove the MaxResults and the FirstResults and add the Projections.rowCount() and call uniqueResult() on the Criteria to get the total number of results that match the query.
The problem we are having is that our application is using projections within some of the queries. When these queries are executed and try and perform the Criteria.uniqueResult() we get the following exception:
org.hibernate.NonUniqueResultException: query did not return a unique result: 27
at org.hibernate.impl.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:789)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:305)
We could use HQL, but this would introduce hard-coding the queries when a projection is used.
Is there a way to get the Criteria query to do a query like this:
select count(*)
from (select table.id from table
where (table.some_column>0)
group by table.id);
|
|