-->
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.  [ 3 posts ] 
Author Message
 Post subject: NonUniqueResultException from an aggregate query
PostPosted: Thu Dec 09, 2004 6:16 pm 
Newbie

Joined: Wed Dec 01, 2004 4:51 pm
Posts: 5
Pure aggregate queries return single row results. What am I missing?

Thanks

Hibernate version: Hibernate 2.1.6

Mapping documents:
<hibernate-mapping>

<class name="com.robico.data.billing.InvoiceItemBO" table="invoice_item">

<id name="id" type="int" unsaved-value="0" >
<column name="item_id" sql-type="int(6) unsigned" not-null="true"/>
<generator class="identity"/>
</id>
<property name="charge">
<column name="charge" sql-type="double" not-null="true"/>
</property>
<property name="resourceUsageId" column="cdr_id" type="int" insert="false" update="false" not-null="true"/>
<many-to-one name="chargeSource"
class="com.robico.billing.asterisk.data.AsteriskChargeBO"
column="charge_id" cascade="none"/>
<many-to-one name="account"
class="com.robico.data.billing.AccountBO"
column="account_id" cascade="all"/>
<many-to-one name="resourceUsage"
class="com.robico.data.billing.ResourceUsageBO"
column="cdr_id" cascade="none"/>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="com.robico.data.billing.ResourceUsageBO" table="cdr">
<id name="id" type="string" unsaved-value="0" >
<column name="uniqueID" sql-type="varchar(32)" not-null="true"/>
<generator class="native"/>
</id>
<property name="usageDate">
<column name="callDate" sql-type="datetime" not-null="true"/>
</property>
<property name="usageUnits" type="double" column="billableDuration" not-null="true"/>
<property name="resourceName" type="string" column="accountCode" not-null="false"/>
<component name="displayDetails"
class="com.robico.billing.asterisk.data.CdrDetails">
<property name="callCost" type="double" column="callCost" not-null="false"/>
<property name="callDisposition" type="string" column="callDisposition" not-null="false"/>
<property name="calledNumber" type="string" column="calledNumber" not-null="true"/>
<property name="callerId" type="string" column="callerID" not-null="false"/>
<property name="endDate" type="calendar" column="endDate" not-null="true"/>
</component>
</class>
<query name="com.robico.data.billing.ResourceUsageBO.getLatest">
from com.robico.data.billing.ResourceUsageBO as usage
where usage.id > ?
</query>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

String maxId = ( String )
session.createQuery( "select max(resourceUsageId) from com.robico.data.billing.InvoiceItemBO" ).uniqueResult();


Full stack trace of any exception that occurs:

net.sf.hibernate.NonUniqueResultException: query did not return a unique result: 11
at net.sf.hibernate.impl.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:559)
at net.sf.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:550)
at com.robico.billing.asterisk.AsteriskChargeManager.createInvoiceItems(AsteriskChargeManager.java:63)
at com.robico.billing.asterisk.AsteriskChargeManager$1.run(AsteriskChargeManager.java:47)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)


Name and version of the database you are using:

MySql 4.0.18

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 10, 2004 2:35 pm 
Newbie

Joined: Wed Dec 01, 2004 4:51 pm
Posts: 5
Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 10, 2004 2:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Check the generated SQL


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.