I'm reading through chap. 7 of Hibernate In Action and simply trying to count a field exactly like 7.4.2 describes, only it's not working correclty.
Here's my method:
Code:
public Integer getCaseTotal(Order order, Date beginDate, Date endDate)
{
Session s = HibernateUtil.getCurrentSession();
Integer count = (Integer)s.createQuery("select count(o.PickList.OrderItems) from Order o where o.Id = :id and o.SentDate between :bd and :ed")
.setLong("id", order.getId())
.setDate("bd", beginDate)
.setDate("ed", endDate)
.uniqueResult();
return count;
}
Here's the query that is returned:
Code:
select count(.) as col_0_0_ from sr_order order0_, sr_inv_pick_list picklist1_, sr_inv_pick_list_detail orderitems2_ where picklist1_.inv_pick_list_id=orderitems2_.inv_pick_list_id and order0_.order_id=picklist1_.inv_pick_list_id and order0_.order_id=? and (order0_.sent_date between ? and ?)
...which results in an exception being thrown that the query can't be parsed.
However, if I change it to count(*) it returns a query that is executable...but incorrect for my needs.
"PickList.OrderItems" is definitely a valid collection of OrderItem objects belonging to the PickList object and the PickList belongs to the Order object...and they are all thustly related in the mapping documents. I'm doing other selects with the same objects (without aggregates) w/o a problem.
Any ideas? This kills my report...I'm not sure how else to go forward w/ this.
Hibernate version: 3.1
Name and version of the database you are using: MSSQL 2000