-->
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.  [ 2 posts ] 
Author Message
 Post subject: retrieve all the criteria results in one batch
PostPosted: Thu Apr 27, 2006 1:32 pm 
Newbie

Joined: Fri Apr 21, 2006 11:25 am
Posts: 3
1.0.2

Mapping documents:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="WTECBSC.VO.ItemDetails,WTECBSC" table="ITEM_DETAILS">

    <composite-id name="ID" class="WTECBSC.VO.ItemDetailsCompositeID,WTECBSC">
      <key-many-to-one name="ItemId" column="item_id" class="WTECBSC.VO.Item,WTECBSC" />
      <key-property column="language_code" type="String" name="LanguageCode" />
    </composite-id>   
      
      <property column="NAME" type="String" name="Name" not-null="true" length="50" />
      <property column="MODEL" type="String" name="Model" not-null="true" length="50" />
      <property column="DESCRIPTION" type="String" name="Description" not-null="true" length="7200" />
      <property column="MAIN_FEATURES" type="String" name="MainFeatures" not-null="true" length="7200" />
      <property column="SPECIFICATIONS" type="String" name="Specifications" not-null="true" length="7200" />
      
   </class>
</hibernate-mapping>



Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="WTECBSC.VO.Item,WTECBSC" table="ITEM">

      <id name="ItemId" column="ITEM_ID" type="Decimal" unsaved-value="0">
         <generator class="native"/>
      </id>
      <bag name="ClientCoreList" inverse="true" lazy="true" >
         <key column="ITEM_ID" />
         <one-to-many class="WTECBSC.VO.ClientCore,WTECBSC" />
      </bag>
      <bag name="ItemDetailsList" inverse="true" lazy="true"         
                access="NHibernate.Generics.GenericAccessor, NHibernate.Generics">
         <key column="item_id" />
         <one-to-many class="WTECBSC.VO.ItemDetails,WTECBSC" />
      </bag>
    <bag name="ItemPriceLevelList" inverse="true" lazy="true"           
                access="NHibernate.Generics.GenericAccessor, NHibernate.Generics">
      <key column="item_id" />
      <one-to-many class="WTECBSC.VO.ItemPriceLevel,WTECBSC" />
    </bag>
    <bag name="ItemProfileList" inverse="true" lazy="true" >
         <key column="ITEM_ID" />
         <one-to-many class="WTECBSC.VO.ItemProfile,WTECBSC" />
      </bag>
      <bag name="PurchaseOrderTransactionList" inverse="true" lazy="true" >
         <key column="ITEM_ID" />
         <one-to-many class="WTECBSC.VO.PurchaseOrderTransaction,WTECBSC" />
      </bag>
      <bag name="TransactionList" inverse="true" lazy="true" >
         <key column="ITEM_ID" />
         <one-to-many class="WTECBSC.VO.Transaction,WTECBSC" />
      </bag>
      <bag name="TransactionSavedList" inverse="true" lazy="true" >
         <key column="ITEM_ID" />
         <one-to-many class="WTECBSC.VO.TransactionSaved,WTECBSC" />
      </bag>
      <many-to-one name="SupplierId" column="SUPPLIER_ID" class="WTECBSC.VO.Supplier,WTECBSC" />
      <many-to-one name="CategoryId" column="CATEGORY_ID" class="WTECBSC.VO.Categories,WTECBSC" />
      <property column="SKU" type="String" name="Sku" not-null="true" length="50" />
      <property column="LOGO" type="String" name="Logo" length="255" />
      <property column="STATUS" type="Boolean" name="Status" not-null="true" />
      <property column="PRICE" type="Decimal" name="Price" not-null="true" />
      <property column="INVENTORY" type="Decimal" name="Inventory" not-null="true" />
      <property column="SHIPPING_CHARGE" type="Decimal" name="ShippingCharge" not-null="true" />
      <property column="CREATION_DATE" type="DateTime" name="CreationDate" not-null="true" />
      <property column="MODIFY_DATE" type="DateTime" name="ModifyDate" not-null="true" />
      
   </class>
</hibernate-mapping>






ItemDetails has attributes of an item. So what I want to do is search on say the features column. I want it to return all the items that have that features value....The problem is that when I profile the SQL what it does is that it does the search inside the ItemDetails table. And than it runs a different SQL query to instantiate each individual item. So if the first search returns 300 items than 300 queries are run after that to fill all the item objects.

Code:
ICriteria criteria = NSession.CreateCriteria(typeof(Item)).CreateAlias("ItemDetailsList", "dtls")
                        .Add(Expression.Like("dtls.MainFeatures", lstKeywords[0], MatchMode.Anywhere));

ICriteria criteria = NSession.CreateCriteria(typeof(ItemDetails)).Add(Expression.Like("MainFeatures", lstKeywords[0], MatchMode.Anywhere));




Both of those cause that exact same thing to happen....The only way I can think of to remedy this. Is to instead of making the Item field in itemdetails a

<key-many-to-one name="ItemId" column="item_id" class="WTECBSC.VO.Item,WTECBSC" />

is to make it a property instead. That way it returns a list of decimals and than I can do a criteria get on all the ids for the item table (which only takes one call)

what I would RATHER have it do. Is create a SINGLE sql query based on my search paramters in the itemdetails object and from that be able to build all the returned items.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 2:48 pm 
Newbie

Joined: Fri Apr 21, 2006 11:25 am
Posts: 3
actually is there just a way in general to have everything retrieved in a single go...

like lets say I have a list of 300 item ids and I want two of the lists filled as well.

I know if I was doing this with my OWN written DA I would just do a select join on the other two tables get all the information back in one single select and than fill the objects.

How can I get nhibernate to do this?


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

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.