-->
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.  [ 2 posts ] 
Author Message
 Post subject: Projections.rowCount returns incorrect value
PostPosted: Wed May 18, 2005 5:04 am 
Newbie

Joined: Mon Jul 12, 2004 2:52 am
Posts: 17
Hibernate version: 3.0.2

Mapping documents:
Code:
   <class name="Bookings" table="bookings">
      <id name="id" column="id" type="string" >
         <generator class="assigned"/>
      </id>
      <set name="bookDetail" table="bookdetail" inverse="true" lazy="true">
         <key>
            <column name="bookId"/>
         </key>
         <one-to-many class="BookDetail"/>
      </set>
   </class>

   <class name="BookDetail" table="bookdetail">
      <id name="id" column="id" type="java.lang.Integer" >
         <generator class="identity"/>
      </id>
   </class>


i create a DetachedCriteria to query the database, in which both parent and child are involved, e.g.:
Code:
DetachedCriteria c = DetachedCriteria.forClass(Bookings.class)
   .add(Expression.eq("createdBy", "AAA"))
   .createCriteria("bookDetail")
      .add(Expression.eq("title", "BBB");

then following query is run:
Code:
int recCnt = ((Integer) c.getExecutableCriteria(HibernateUtil.getSession())
   .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
   .setProjection(Projections.projectionList().add(Projections.rowCount()))
   .list().iterator().next()).intValue();


the DetachedCriteria is then re-used afterwards to get all distinct Bookings.

the recCnt is not counting the number of distinct bookings but suming up the number of distinct records after the join.

How could i fix it?


Top
 Profile  
 
 Post subject: or...
PostPosted: Fri May 20, 2005 12:19 am 
Newbie

Joined: Mon Jul 12, 2004 2:52 am
Posts: 17
is there any work around...

the least thing i want is to create another query to do the counting


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