I'm having a related problem:
2 Scenarios
Scenario 1 :
Code:
<!-- A list of roles which can be assigned to a user -->
<set name="AvailableRoles" lazy="true">
<key/>
<one-to-many class="Role"/>
<loader query-ref="SQLGetAvailableRoles"/>
</set>
<sql-query name="SQLGetAvailableRoles">
<load-collection alias="" role="User.AvailableRoles">
</load-collection>
SELECT * FROM roles r WHERE r.id NOT IN
(SELECT rolepointer FROM userroles WHERE userpointer=:ID)
</sql-query>
This actually executes, the log files say all entities are populated, but the collection remains empty.
After a little browsing around, I found the following:
http://wiki.nhibernate.org/browse/NH-794 which seems to give the answer.
So after a few changes, we get to
Scenario 2 :Code:
<sql-query name="SQLGetAvailableRoles">
<load-collection alias="" role="User.AvailableRoles">
<return-property name="key" column="id"/>
</load-collection>
SELECT * FROM roles r WHERE r.id NOT IN
(SELECT rolepointer FROM userroles WHERE userpointer=:ID)
</sql-query>
As soon as I add in the <return-property> elements the whole thing is failing with - "Column index out of range".
The problem occurs on Loader.cs at GetKeyFromResultSet, where it seems nHibernate is looking for (in my case) a field named id2_0_ where the result set contains the plain field names from the table.
So, I'm guessing I'm doing something wrong when it comes to specifying an alias for field or something.
Will keep chipping away at it.
Hope someone can help.