Ayende Rahien wrote:
I am willing to bet that there is a SELECT N+1 that is happening behind the scenes.
Make sure that your assoications are always lazy, enable SQL logs and check to see what is going on.
Okay, this idea sounds like it's on the right track. What's happening is that I have an Item object, and each Item object has Locasion, CasNum and Vendor objects. Lazy loading doesn't seem like it would help here, because I am needing to display all of this data for the user. It loads all of the Item objects with one single select and then loads the child objects using individual selects.
In my mapping file, I have it set to do joins for these child objects, which I think would perform better. What might be causing it to not do joins?
Below is my mapping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="data" namespace="data" default-cascade="save-update">
<class name="Item" table="current_inventory">
<id name="ID" column="item_id" type="Int64" unsaved-value="-1">
<generator class="sequence">
<param name="sequence">item_id_seq</param>
</generator>
</id>
<property name="Description" column="description" type="string" />
<property name="Purity" column="purity" type="double" />
<property name="cState" column="state" type="Char" />
<property name="NFPAHealth" column="nfpa_health" type="short" />
<property name="NFPAFlammability" column="nfpa_flammable" type="short" />
<property name="NFPAReactivity" column="nfpa_reactivity" type="short" />
<property name="CatNum" column="cat_num" type="string" />
<property name="LotNum" column="lot_num" type="string" />
<property name="Amount" column="amount" type="Decimal" />
<property name="Quant" column="quant" type="Decimal" />
<property name="Units" column="units" type="string" />
<property name="Notes" column="notes" type="string" />
<property name="LastAction" column="last_change_action" type="string" />
<property name="LastPurchased" column="last_purchased" type="DateTime" />
<property name="LastChange" column="last_change" type="DateTime" />
<property name="Hazard" column="hazard" type="string" />
<property name="PurchasePrice" column="last_purchase_price" type="Decimal" />
<many-to-one name="Location" class="Location" column="loc_id" fetch="join"/>
<many-to-one name="Vendor" class="Vendor" column="vendor_id" cascade="save-update" fetch="join"/>
<many-to-one name="LastUser" class="User" column="last_change_user" cascade="save-update" fetch="join"/>
<many-to-one name="CASNum" class="CASNum" column="cas_id" cascade="save-update" fetch="join"/>
</class>
</hibernate-mapping>