-->
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: Mapping Confusion and Lazy Loading .
PostPosted: Wed Sep 13, 2006 6:06 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Hibernate version: NHibernate v1.0.2

Mapping documents:

1. Item.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="nhExhibition.Business.Item, nhExhibition.Business" table="Item">
<id name="Id" type="Int32" unsaved-value="0">
<column name="iditem" length="4" sql-type="int" not-null="true" unique="true" index="PK_Item"/>
<generator class="native" />
</id>
<property name="Itemname" type="String">
<column name="itemname" sql-type="varchar" not-null="true"/>
</property>
<property name="Itemprice" type="Decimal">
<column name="itemprice" length="4" sql-type="smallmoney" not-null="true"/>
</property>
<property name="Itemquality" type="String">
<column name="itemquality" length="50" sql-type="varchar" not-null="true"/>
</property>
<property name="Itembid" type="Decimal">
<column name="itembid" length="4" sql-type="smallmoney" not-null="true"/>
</property>
<property name="Custverifycode" type="String">
<column name="custverifycode" sql-type="varchar" not-null="true"/>
</property>
<many-to-one name="UserAccount" class="nhExhibition.Business.UserAccount, nhExhibition.Business">
<column name="iduser" length="16" sql-type="uniqueidentifier" not-null="false"/>
</many-to-one>
<bag name="ItemDetails" inverse="true" lazy="true">
<key column="iditem"/>
<one-to-many class="nhExhibition.Business.Item, nhExhibition.Business"/>
</bag>
<bag name="iditemidkeywords" table="Item_Keyword" inverse="false" lazy="true">
<key>
<column name="iditem" length="4" sql-type="int" not-null="true"/>
</key>
<many-to-many class="nhExhibition.Business.Keyword, nhExhibition.Business">
<column name="idkeyword" length="4" sql-type="int" not-null="true"/>
</many-to-many>
</bag>
<bag name="iditemidbrands" table="Item_Brand" inverse="false" lazy="true">
<key>
<column name="iditem" length="4" sql-type="int" not-null="true"/>
</key>
<many-to-many class="nhExhibition.Business.Brand, nhExhibition.Business">
<column name="idbrand" length="4" sql-type="int" not-null="true"/>
</many-to-many>
</bag>
<bag name="Questions" inverse="true" lazy="true">
<key column="iditem"/>
<one-to-many class="nhExhibition.Business.Question, nhExhibition.Business"/>
</bag>
<bag name="Description_infos" inverse="true" lazy="true">
<key column="iditem"/>
<one-to-many class="nhExhibition.Business.Description_info, nhExhibition.Business"/>
</bag>
<bag name="iditemidcategories" table="Item_Category" inverse="false" lazy="true">
<key>
<column name="iditem" length="4" sql-type="int" not-null="true"/>
</key>
<many-to-many class="nhExhibition.Business.Category, nhExhibition.Business">
<column name="idcategory" length="4" sql-type="int" not-null="true"/>
</many-to-many>
</bag>
</class>
</hibernate-mapping>

2. Item.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="nhExhibition.Business.Category, nhExhibition.Business" table="Category">
<id name="Id" type="Int32" unsaved-value="0">
<column name="idcategory" length="4" sql-type="int" not-null="true" unique="true" index="PK_Category"/>
<generator class="native" />
</id>
<property name="Cat" type="String">
<column name="cat" length="255" sql-type="varchar" not-null="true"/>
</property>
<property name="Status" type="Boolean">
<column name="status" length="1" sql-type="bit" not-null="true"/>
</property>
<many-to-one name="cathasparent" class="nhExhibition.Business.Category, nhExhibition.Business">
<column name="cathasparent" length="4" sql-type="int" not-null="false"/>
</many-to-one>
<bag name="cathasparentCategories" inverse="true" lazy="true">
<key column="cathasparent"/>
<one-to-many class="nhExhibition.Business.Category, nhExhibition.Business"/>
</bag>
<bag name="idcategoryiditems" table="Item_Category" inverse="false" lazy="true">
<key>
<column name="idcategory" length="4" sql-type="int" not-null="true"/>
</key>
<many-to-many class="nhExhibition.Business.Item, nhExhibition.Business">
<column name="iditem" length="4" sql-type="int" not-null="true"/>
</many-to-many>
</bag>
</class>
</hibernate-mapping>


Name and version of the database you are using: SQL SERVER EXPRESS 2005

Development Environment:ASP.NET v2.0 - C#

Dear members,

I have these 2 hbm files which have many relationships with other classes.
While i'm enabling the lazy loading "lazy=true", all the collection objects of the Category class are being loaded, but the problem is that these collections also are loading their own collections .. which resuult of loading all the database !!!
How can we fix that problem ?

Beside, while using the property names in the HQL to retrieve properties, the resultant IList objects have a structure that does not fit with the GridViews data fields ! The list of objects retrieved does not have a property to Use !! What about that ?

Regards,

Jojo

_________________
In Code We Trust


Top
 Profile  
 
 Post subject: Re: Mapping Confusion and Lazy Loading .
PostPosted: Thu Sep 21, 2006 3:07 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
jojorico wrote:
Hibernate version: NHibernate v1.0.2

Mapping documents:

1. Item.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="nhExhibition.Business.Item, nhExhibition.Business" table="Item">


I have these 2 hbm files which have many relationships with other classes.
While i'm enabling the lazy loading "lazy=true", all the collection objects of the Category class are being loaded, but the problem is that these collections also are loading their own collections .. which resuult of loading all the database !!!
How can we fix that problem ?

First of all, How do You determine that the lists are loaded by default? By monitoring SQL database activity? Using debugger do inspect properties does trigger lazy loading...

Second, as You are using version 1.0.2, You might want to add lazy="true" to class mapping also... Or consider using never version of NHibernate (next beta should be out soon)

jojorico wrote:
Beside, while using the property names in the HQL to retrieve properties, the resultant IList objects have a structure that does not fit with the GridViews data fields ! The list of objects retrieved does not have a property to Use !! What about that ?

Sorry, I've not yet tried to use the data binding... But there are quite many posts in this forum about using NHibernate data with data binding.

Gert

_________________
If a reply helps You, rate it!


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.