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