-->
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: NHibernate generates too many statements
PostPosted: Thu May 03, 2012 8:36 am 
Newbie

Joined: Fri Mar 23, 2012 4:53 pm
Posts: 2
Hi,
I have a table InventoryObject with two foreign-keys to Device and Room.
Now I want to select all InventoryObjects with their Room and Device.

My T-SQL query would be: select * from InventoryObject i left join device d on i.deviceid=d.deviceid left join room r on i.roomid=r.roomid;

But NHibernate generates a Select statement for the Inventories and than one statement per Room and Device.
How can i force NHibernate to generate only one statement?

I use Nhibernate 3.2 and Linq to query the DB.
My command to get all objects is: Session.Query<T>().ToList()

My InventoryObject Mapping-File:
Code:
  <class name="InventoryObject" table="InventoryObject" lazy="true" >
    <id name="InventoryID" column="InventoryID" type="long">
      <generator class="identity" />
    </id>
    <many-to-one insert="true" column="DeviceID" update="true" lazy="false" name="Device" not-null="true" class="Device">
    </many-to-one>
   
    <many-to-one insert="true" column="RoomID" update="true" lazy="false" name="Room" not-null="true" class="Room" >
    </many-to-one>

   
    <bag name="Archives" inverse="true" cascade="none" lazy="true" fetch="join">
      <key column="InventoryID" />
      <one-to-many class="Archive" />
    </bag>
    <bag name="Tickets" inverse="true" cascade="none" lazy="true">
      <key column="InventoryID" />
      <one-to-many class="Ticket"  />
    </bag>
  </class>


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.