-->
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.  [ 3 posts ] 
Author Message
 Post subject: Recurvive relation and many-to-many not loading Eagerly
PostPosted: Thu Jan 26, 2006 2:07 am 
Newbie

Joined: Sun Jul 24, 2005 2:19 am
Posts: 7
I have a class with recursive relation to itself (categories and sub categories). Within each category I have a many to many association with artifact class.

I am trying to load the whole object graph in one call - but NH does not load the artifacts eagerly. Is it due to the recursive relation in parent category class?


Hibernate version: 1.0.2

Mapping documents:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Spider.DocumetManagement.DataEntities.ArtifactProperty, Spider.DocumetManagement.DataEntities" proxy="Spider.DocumetManagement.DataEntities.IArtifactProperty, Spider.DocumetManagement.DataEntities" lazy="true" table="ARTIFACT_PROPERTY">
<id name="ID" access="nosetter.lowercase" column="ID" type="Int32" unsaved-value="-1">
<generator class="identity" />
</id>
<version name="ObjectVersion" access="nosetter.lowercase" column="OBJECT_VERSION" type="Int32" />
<property name="PropName" column="PROP_NAME" length="100" not-null="true" />
<property name="PropValue" column="PROP_VALUE" length="100" />
<property name="PropHtml" column="PROP_HTML" length="100000" />
<many-to-one name="Artifact" class="Spider.DocumetManagement.DataEntities.Artifact, Spider.DocumetManagement.DataEntities" column="ARTIFACT_ID" not-null="true" />
</class>
<class name="Spider.DocumetManagement.DataEntities.Artifact, Spider.DocumetManagement.DataEntities" proxy="Spider.DocumetManagement.DataEntities.IArtifact, Spider.DocumetManagement.DataEntities" lazy="true" table="ARTIFACT">
<id name="ID" access="nosetter.lowercase" column="ID" type="Int32" unsaved-value="-1">
<generator class="identity" />
</id>
<version name="ObjectVersion" access="nosetter.lowercase" column="OBJECT_VERSION" type="Int32" />
<property name="Title" column="TITLE" length="255" not-null="true" />
<property name="PrimaryLink" column="PRIMARY_LINK" length="255" not-null="true" />
<property name="MoreInfoLink" column="MORE_INFO_LINK" length="255" />
<property name="PrimaryHtml" column="PRIMARY_HTML" length="1000000" />
<property name="SecondaryHtml" column="SECONDARY_HTML" length="1000000" />
<property name="PrimaryImageUrl" column="PRIMARY_IMAGE_URL" length="255" />
<property name="ThumbImageUrl" column="THUMB_IMAGE_URL" length="255" />
<bag name="Properties" lazy="true" cascade="all">
<key column="ARTIFACT_ID" />
<one-to-many class="Spider.DocumetManagement.DataEntities.ArtifactProperty, Spider.DocumetManagement.DataEntities" />
</bag>
<bag name="Categories" table="CATEGORY_ARTIFACT" lazy="true" cascade="all" inverse="true">
<key column="ARTIFACT_ID" />
<many-to-many class="Spider.DocumetManagement.DataEntities.Category, Spider.DocumetManagement.DataEntities" column="CATEGORY_ID" />
</bag>
</class>
<class name="Spider.DocumetManagement.DataEntities.Category, Spider.DocumetManagement.DataEntities" proxy="Spider.DocumetManagement.DataEntities.ICategory, Spider.DocumetManagement.DataEntities" lazy="true" table="CATEGORY">
<id name="ID" access="nosetter.lowercase" column="ID" type="Int32" unsaved-value="-1">
<generator class="identity" />
</id>
<version name="ObjectVersion" access="nosetter.lowercase" column="OBJECT_VERSION" type="Int32" />
<property name="Title" column="TITLE" length="255" not-null="true" />
<many-to-one name="ParentCategory" class="Spider.DocumetManagement.DataEntities.Category, Spider.DocumetManagement.DataEntities" column="PARENT_CATEGORY_ID" />
<bag name="Children" lazy="true" outer-join="true" cascade="save-update">
<key column="PARENT_CATEGORY_ID" />
<one-to-many class="Spider.DocumetManagement.DataEntities.Category, Spider.DocumetManagement.DataEntities" />
</bag>
<bag name="Artifacts" table="CATEGORY_ARTIFACT" lazy="true" cascade="all">
<key column="CATEGORY_ID" />
<many-to-many class="Spider.DocumetManagement.DataEntities.Artifact, Spider.DocumetManagement.DataEntities" column="ARTIFACT_ID" />
</bag>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
ISession session = CreateSession( );
ICriteria criteria = session.CreateCriteria( typeof(Category) );
criteria.Add( Expression.Eq( "ID", id ) );
criteria.SetFetchMode( "Artifacts", FetchMode.Eager );
criteria.SetFetchMode( "Artifacts.Properties", FetchMode.Eager );
IList list = criteria.List( );


Full stack trace of any exception that occurs:

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 2:05 pm 
Newbie

Joined: Sun Jul 24, 2005 2:19 am
Posts: 7
no solution to this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 4:49 am 
Regular
Regular

Joined: Tue Mar 15, 2005 12:38 pm
Posts: 73
Location: Bucharest
Don't see why shouldn't work. Try using CreateAlias and set fetch model on it or maybe CreateCriteria on the original criteria (although I doubt that fetching mode set on subqueries is handled).

Code:
ISession session = CreateSession( );
ICriteria criteria = session.CreateCriteria( typeof(Category) );
criteria.Add( Expression.Eq( "ID", id ) );

ICriteria alias = criteria.CreateAlias("Artifacts", "a")
     .SetFetchMode( "a.Properties", FetchMode.Eager );

IList list = criteria.List( );



Or try using HQL with inner join fetch.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.