NHibernate version: 1.0.2
Hello all.
I'm seeing what looks like a misplaced SQL '?' parameter from a variable placed in the 'having' clause of an HQL query.
In its simplest form, the HQL query is:
Code:
select o.sender.id from Order o group by o.sender having count(o) >= :orderCount
Where there are two tables, OrderTable mapped as the persistent object Order and Address mapped as Address.
o.sender is an instance of Address, and is mapped as a uni-directional many-to-one from Order to Address thus:
Code:
<many-to-one name="sender" access="field" fetch="select" column="senderaddrid" not-null="true" />
So the query is trying to return the ids of Address objects that
orderCount or more instances of Order existing.
Anyway, the problem is that the SQL generated by NHibernate comes out as:
Code:
select order0_.senderaddrid as x0_0_ from OrderTable order0_ where ? group by order0_.senderaddrid having (count(order0_.orderid)>=)
instead of the expected:
Code:
select order0_.senderaddrid as x0_0_ from OrderTable order0_ group by order0_.senderaddrid having (count(order0_.orderid)>=?)
which does run as expected in the Access database at the back end.
If I put a dummy 'where' clause into the HQL like this:
Code:
select o.sender.id from Order o where o.id <> 0 group by o.sender having count(o) >= :orderCount
it still comes out like this:
Code:
select order0_.senderaddrid as x0_0_ from OrderTable order0_ where (order0_.orderid<>0)? group by order0_.senderaddrid having (count(order0_.orderid)>=)
(I've also tried making the 'group by' be on
o.sender.id instead, but the end result is the same.)
Can anyone shed any light on this? The documentation gives an example of using aggregate functions in the having clause, but only with a constant and not a variable. Am I approaching the problem from the wrong way round - should I be selecting from the Address table and putting a one-to-many link from Address to Order (which is uni-directional from the other way at the moment)?
Many thanks,
Richard.