-->
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.  [ 4 posts ] 
Author Message
 Post subject: Can't get lazy loading to work
PostPosted: Sat Oct 01, 2005 4:58 am 
Newbie

Joined: Sat Sep 17, 2005 5:48 am
Posts: 9
I've tried for days to get my countrys to not load the cities and states, however ive tried a few things and i dont seem to get anywhere. When I check the property values in my debugger, sure enough i can see everything.

Here's my xml file for countries:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
  <class name="DAL.Country, DAL" table="Countries" lazy="true">
    <id name="Id" type="Int32" column="country_id">
      <generator class="identity" />
    </id>
    <bag name="Cities" inverse="true">
      <key column="country_id" />
      <one-to-many class="DAL.City, DAL" />
    </bag>
    <property name="countryprefix" column="country_prefix" type="String" />
    <property name="countryname" column="countryname" type="String" />
    <bag name="States" inverse="true">
      <key column="country_id" />
      <one-to-many class="DAL.State, DAL" />
    </bag>
  </class>
</hibernate-mapping>


And my code:
Code:
session = Global.Factory;
IList countries = null;

Country country = new Country();
string query = "from DAL.Country";
countries = session.Find(query);
session.Close();


Can anyone see something I cant?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 6:16 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
First, you should add lazy="true" to your <bag> elements.
Second, looking at a property through the debugger might well cause the collection to initialize.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 06, 2005 9:17 pm 
OK, I tried your first suggestion by setting the bag to have the lazy="true' property. Still no dice.

However i'm perturbed by the idea that my debugger would by overriding my lazy loading. And if i cant see it in my debugger how am i supposed to verify the values being returned (unless i write them all to screen) which I could do. Anyone know of this happening in the vs debugger.


Top
  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 3:49 am 
Contributor
Contributor

Joined: Sun Jun 26, 2005 5:03 am
Posts: 51
Location: London, UK
If you are using SQL Server, you can use the profiler to see when the SQL is hitting the database, otherwise you can turn on the SQL logging in NHibernate and again see that the SQL hits the database when you first access the collection.

_________________
Paul Hatcher
NHibernate Team


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