Have anyone positive expirience with one-to-many and sql-queries? I
can't produce any valid. Seem to me NHibernate fails in this area

   <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 seem to mee
it needs some additional fields for keys but I have no ideas how to
specify them). 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.
Only this code fixes duplicates:
ISet<T> results = new HashedSet<T>(query.List<T>());


But it seem like workaround not like valid solution

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to