-->
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.  [ 8 posts ] 
Author Message
 Post subject: Self referencing relationship
PostPosted: Thu May 12, 2005 11:10 am 
Newbie

Joined: Wed May 11, 2005 6:14 pm
Posts: 10
For a simple example, let's say you have a Department table, which has some other object references (perhaps to a DepartmentType table and some other stuff). This table also has a self reference (nullable) to another Department, which is its parent department. The class also has a "children" bag called SubDepartments, which is set to lazy load.

I have this working fine as a many-to-one relationship from the class to itself through a column named parent_id. My question is, how can you make this a lazy loading relationship, so that you don't get back this huge graph of parents/children by loading a deeply nested department?

As I recall, Hibernate supports lazy="true" on many-to-one relationships, but this doesn't work in NHibernate. Is this something I should worry about, or am I missing something?

I can provide a mapping and schema example if necessary. Thanks!


Top
 Profile  
 
 Post subject: Re: Self referencing relationship
PostPosted: Thu May 12, 2005 11:32 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
ironcladlou wrote:
As I recall, Hibernate supports lazy="true" on many-to-one relationships, but this doesn't work in NHibernate. Is this something I should worry about, or am I missing something?


That's outdated information, NHibernate supports lazy-loading of <many-to-one> since 0.6 or so.


Top
 Profile  
 
 Post subject: Re: Self referencing relationship
PostPosted: Thu May 12, 2005 12:10 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
IIRC, lazy="true" on <many-to-one> (and <one-to-many>) relationships work in NHibernate (0.8.2.0).

Release notes wrote:
Added lazy="true" as short hand for proxy="full type name"

Cf. http://sourceforge.net/project/shownote ... _id=326230

And "Proxy" is the way to lazy load <many-to-one>.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: Re: Self referencing relationship
PostPosted: Thu May 12, 2005 1:08 pm 
Newbie

Joined: Wed May 11, 2005 6:14 pm
Posts: 10
KPixel wrote:
IIRC, lazy="true" on <many-to-one> (and <one-to-many>) relationships work in NHibernate (0.8.2.0).

Release notes wrote:
Added lazy="true" as short hand for proxy="full type name"

Cf. http://sourceforge.net/project/shownote ... _id=326230

And "Proxy" is the way to lazy load <many-to-one>.


Hmm, I must have misidentified an error then (i.e., I may have had some other problem with the mapping file and wrongly attributed it to the lazy property). Thanks, I will definitely try this again when I get home!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 2:17 pm 
Beginner
Beginner

Joined: Wed Jun 08, 2005 4:59 pm
Posts: 27
In 1.0.2, if I try to put a lazy="true" attribute on a <many-to-one ...> declaration, I get an error "The 'lazy' attribute is not declared". Am I missing something?

Thank you!
-Michael


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 4:54 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
lazy="true" is intended to be used in <class>, not in <many-to-one>.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 6:12 pm 
Beginner
Beginner

Joined: Wed Jun 08, 2005 4:59 pm
Posts: 27
So what does that actually mean? Any reference to that class by another class would automatically be lazy-loaded?

-MT


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 2:49 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.