-->
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: Need help with Lazy Loading of Single Point Association
PostPosted: Tue Jan 03, 2006 7:46 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

I am new to NHibernate and am using Ver 1.0.1.0
I have a simple table UserMaster that has a column ReportsTo that is an FK to the UserMaster table itself. Following is my mapping file:

<?xml version='1.0' encoding='utf-8'?>
<hibernate-mapping
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
namespace='DAL'
assembly='DAL' xmlns='urn:nhibernate-mapping-2.0'>
<class
lazy='true'
name='UserMaster'
table='UserMaster'>
<id
name='UserName'
column='UserName'>
<generator
class='assigned' />
</id>
<property
name='FName'
column='FName'
not-null='true' />
<property
name='LName'
column='LName' />
<many-to-one
name='ReportsTo'
class='UserMaster'
column='ReportsTo'
outer-join='auto' />
<set
name='Reportees'
lazy='true'
inverse='true'>
<key
column='ReportsTo' />
<one-to-many
class='UserMaster' />
</set>
</class>
</hibernate-mapping>

I wrote a simple Console Application to test the Lazy Loading of ReportsTo property.
UserMaster um1 = (UserMaster)session.Get(typeof(UserMaster),"rel");
Console.WriteLine("Number of Reportees: "+um1.Reportees.Count);
Console.WriteLine("Manager FName: "+um1.ReportsTo.FName);

I can see the Reportees collection being correctly lazily loaded (It fires a new query to load the collection). The ReportsTo is returned as a Proxy object but it does not actually load the entity when I access the ReportsTo. As you can see this is a many-to-one relationship.

I have tried but failed to get this lazily loaded. What am I doing wrong.

Thanks in advance,
Job Samuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 8:05 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Are properties and methods of the lazy class all virtual?


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Tue Jan 03, 2006 11:55 pm 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
Thanks, that did it....


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.