-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: sql-query one-to-many
PostPosted: Thu Feb 04, 2010 12:15 pm 
Newbie

Joined: Tue Jan 26, 2010 4:49 am
Posts: 6
Location: Belarus, Minsk
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.