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?