In the my recent post I have found that many-to-many in NHibernate doesn't work at all.
Have anyone positive expirience with one-to-many and sql-queries? I can't produce any valid. Seem to me NHibernate also fails in this area
Code:
<class name="Message" table="TBL_MESSAGE" >
<id name="Id" type="Int32" column="MESSAGE_ID">
<generator class="identity"/>
</id>
<property name="Subject" column="SUBJECT" type="String"/>
<bag name="Documents" table="TBL_DOCUMENT" lazy="true" fetch="join" outer-join="true">
<key column="RECORD_ID" ></key>
<one-to-many class="Document"/>
</bag>
</class>
<sql-query name="ByIds">
<return alias="msg" class="Message"/>
<return-join alias="doc" property="msg.Documents"/>
SELECT msg.MESSAGE_ID as {msg.Id},
msg.SUBJECT as {msg.Subject},
{doc.*}
FROM TBL_MESSAGE msg
LEFT JOIN
TBL_DOCUMENT doc ON doc.RECORD_ID = msg.MESSAGE_ID
ORDER BY msg.SUBJECT
</sql-query>
<class name="Document" table="TBL_DOCUMENT" >
<id name="Id" type="Int32" column="DOCUMENT_ID">
<generator class="identity"/>
</id>
<property name="ParentId" column="RECORD_ID" type="Int32"/>
<property name="FileName" column="FILE_NAME" type="String"/>
</class>
this is the only xml that produces valid sql without exceptions (for example {doc.element.Id}, {doc.element.ParentId}) will fail. So no selectivity for collecions. But even in this case if 1 message has 2 documents in out result set it will be 2 messages. DistinctRootEntityResultTransformer also causes exceptions when added.