-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SubSelect in from clause
PostPosted: Fri Apr 27, 2007 6:27 pm 
Newbie

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);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.