-->
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.  [ 4 posts ] 
Author Message
 Post subject: Why is count(*) not returing unique Result
PostPosted: Thu Sep 28, 2006 10:30 pm 
Beginner
Beginner

Joined: Wed Oct 05, 2005 12:29 pm
Posts: 22
Hi,

I am wondering why the following:

Query countQuery = getSession().createQuery("select count(*) from Product where companyId = 1");
Integer datasetSize = (Integer) countQuery.uniqueResult();

throws a NonUniqueResultException.

I did a countQuery.list(), and found that the query returns a list of 2 elements. The first is the count result, and the second is a zero Integer.

I am using Hibernate 3.1.2.

Many thanks in advance.

Best regards,
Yee


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 2:41 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Is Product a base class for different types of products?

Set polymorphism="explicit" in Product.hbm.xml for class element.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 3:05 am 
Beginner
Beginner

Joined: Fri Jun 02, 2006 1:23 am
Posts: 27
What happens when you use a criteria?

Code:
Criteria crit = session.createCriteria(Product.class);
crit.setProjection( Projections.rowCount() );
// .. company id stuff, criteria.add( Expression...
Integer i = (Integer) crit.uniqueResult();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 4:37 am 
Beginner
Beginner

Joined: Wed Oct 05, 2005 12:29 pm
Posts: 22
JayeshJ wrote:
Is Product a base class for different types of products?

Set polymorphism="explicit" in Product.hbm.xml for class element.


Yes - it is indeed a base class for another product - CommissionedProduct, which is mapped to a rather complex query with mutable="false".

Hope I am not doing something illegal/not-recommended.

Thanks again.

Yee


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

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.