-->
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: Lazy Load a Many-To-One Relationship?
PostPosted: Thu Jun 16, 2005 4:57 pm 
I have an employee object that has a Manager property. Everytime I use NHibernate to populate an employee it also gets the manager. And then it gets that person's manager and then that person's manager and then....etc.

Can I tell it not to load the manager unless it is needed? I want to lazy load the manager information. This is what my mapping file looks like.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-access="property">
   <class name="Core.Domain.Employee, Core" table="vwEmployees" mutable="false">
      <id name="EmpID" column="EmpID" access="nosetter.camelcase-underscore">
         <generator class="identity" />
      </id>
      <property name="FirstName" column="FirstName" />
      <property name="LastName" column="LastName" />
      <property name="BusinessTitle" column="BusinessTitle" />
      <many-to-one name="ReportsTo" class="Core.Domain.Employee, Core" column="ReportsToID"/>
      <bag name="DirectReports" table="vwEmployees" inverse="true" lazy="true">
         <key column="ReportsToID" />
         <one-to-many class="Core.Domain.Employee, Core" />
      </bag>
   </class>
</hibernate-mapping>


Thanks for your help,
Daren


Top
  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 5:04 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
Employee object must implement proxying:

Code:
<class name="Employee" lazy="true">


or

set outer-join="false" on that m-1 mapping:

Code:
<many-to-one name="Manager" class="Employee" column="ManagerID" outer-join="false" />


-devon


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.